library(tidyverse)
library(hrbrthemes)
library(kableExtra)
library(patchwork)
data <- read.csv('/Users/nishapaudel/Documents/CASP/Data/sept_15_tmm.csv', sep =',', header=T, row.names = 1)
data_gene <- read.csv('/Users/nishapaudel/Documents/CASP/Data/sept_15_tmm.csv', sep =',', header=T) ## I am reading again just to get the genes names
x<- data_gene$X
head(data)
## F_P60_LPS_1 F_P60_LPS_2 M_P60_LPS_2 F_P60_LPS_4 F_P60_LPS_5
## 0610007C21Rik 108.627780 133.153891 93.033594 131.669047 100.179793
## 0610007L01Rik 92.569761 67.963965 66.067335 94.362817 69.873301
## 0610007P08Rik 49.118648 51.319729 47.190954 18.653115 37.041268
## 0610007P14Rik 12.279662 31.901453 8.089878 24.139325 24.413563
## 0610007P22Rik 7.556715 5.548079 1.348313 4.388968 6.734776
## 0610009B22Rik 16.058020 6.935098 26.966259 18.653115 8.418470
## F_P60_LPS_6 M_P60_LPS_7 F_P60_Sal_1 F_P60_Sal_2 F_P60_Sal_3
## 0610007C21Rik 108.497834 89.841177 98.94049 94.51336 87.146593
## 0610007L01Rik 75.409842 83.735466 89.71453 74.56054 85.610970
## 0610007P08Rik 39.243897 32.273044 48.99304 37.80534 36.854947
## 0610007P14Rik 15.389764 7.850200 11.45292 12.60178 16.891851
## 0610007P22Rik 5.386417 6.105711 3.81764 10.50148 4.990774
## 0610009B22Rik 15.389764 7.850200 14.95242 15.75223 18.427473
## F_P60_Sal_4 F_P60_Sal_5 M_P60_Sal_5 F_P60_Sal_7 M_P60_LPS_1
## 0610007C21Rik 114.726769 101.197082 78.32326 110.571009 102.940874
## 0610007L01Rik 75.670848 83.919532 74.72678 92.142507 68.241703
## 0610007P08Rik 42.717414 37.023323 45.95497 36.857003 47.422200
## 0610007P14Rik 7.322985 12.341108 16.38395 24.571335 10.409751
## 0610007P22Rik 4.881990 3.702332 13.18708 7.897929 6.939834
## 0610009B22Rik 20.748458 20.979883 14.78551 16.673406 15.036307
## F_P60_LPS_3 M_P60_LPS_3 M_P60_LPS_4 M_P60_LPS_5 M_P60_LPS_6
## 0610007C21Rik 70.921188 65.576346 64.680899 70.469900 92.937523
## 0610007L01Rik 70.921188 61.477825 77.617078 93.959867 71.621577
## 0610007P08Rik 20.859173 42.351390 27.048376 27.198909 27.284410
## 0610007P14Rik 15.644380 10.929391 14.112196 16.072083 5.968465
## 0610007P22Rik 8.343669 0.000000 4.704065 4.945256 8.526378
## 0610009B22Rik 14.601421 8.197043 11.760163 19.781025 14.494843
## M_P60_Sal_1 M_P60_Sal_2 M_P60_Sal_3 M_P60_Sal_4 F_P60_Sal_6
## 0610007C21Rik 72.559910 97.632458 83.223776 88.700137 288.40569
## 0610007L01Rik 87.152964 77.166548 76.090309 82.037216 64.09015
## 0610007P08Rik 49.048877 36.905740 38.996283 46.224015 18.93573
## 0610007P14Rik 13.376967 16.439830 19.973706 16.240870 45.15443
## 0610007P22Rik 7.296527 8.052162 9.035724 6.246489 17.47913
## 0610009B22Rik 13.376967 13.755776 23.302657 20.821628 68.45994
desired_columns <- c("M_P60_Sal_1", "M_P60_Sal_2", "M_P60_Sal_3", "M_P60_Sal_4", "M_P60_Sal_5")
# Rearrange the columns based on the desired order
data_rearranged_male <- data[, desired_columns]
# Calculate row means for the data frame
row_means <- rowMeans(data_rearranged_male[, -1])
# Create a new data frame with gene names and row means
new_df <- data.frame(male_sal = row_means)
desired_columns_f <- c( "F_P60_Sal_1", "F_P60_Sal_2", "F_P60_Sal_3", "F_P60_Sal_4", "F_P60_Sal_5", "F_P60_Sal_6", "F_P60_Sal_7")
# Rearrange the columns based on the desired order
data_rearranged_f <- data[, desired_columns_f]
# Calculate row means for the data frame
row_means <- rowMeans(data_rearranged_f[, -1])
# Create a new data frame with gene names and row means
new_df_f <- data.frame(female_sal = row_means)
Female_sal<- new_df_f$female_sal
Male_sal <- new_df$male_sal
combined_df <- cbind( Female_sal, Male_sal)
# Calculate row means for the data frame
means <- rowMeans(combined_df)
combined_df_new <- data.frame(x, Female_sal, Male_sal,means)
# order the rows Assuming 'data' is your data frame with a 'mymean' column
data_new <- combined_df_new[order(combined_df_new$means), ]
#select few genes from DF
selected_genes <- c("Crip2","Ddr1","Cebpb","Nr3c1","Arhgef10","Tnfa", "Tlr4", "Ttr", "Il10ra", "Il1a", "Xist", "Tsix","Uty","Dcpp1","Zfp36", "P2ry12","Tgfbr1","Cx3cr1","Ccr5","Ncoa2","Il10", "Cxcl2","Fos","Il1b","Vegfc", "Hnrnpu", "Dusp1","Ccl5","Alox5ap","Adam9","yp11a1","Edn1","Fdxr","Raf1", "Tenc1","Ddx3y","Snrnp200" )
combined_df_new_1 <- combined_df_new[selected_genes, ]
# Select rows by gene names using the %in% operator
selected_rows <- combined_df_new[combined_df_new$x %in%selected_genes, ]
# order the means -> Assuming 'data' is your data frame with a 'mymean' column
data_new <- selected_rows[order(selected_rows$means), ]
# Plot
ggplot(data_new) +
geom_segment( aes(x=x, xend=x, y=Female_sal, yend=Male_sal), color="grey") +
geom_point( aes(x=x, y=Female_sal), color="pink1", size=3 ) +
geom_point( aes(x=x, y=Male_sal), color= "skyblue1", size=3 ) +
coord_flip()+
theme_ipsum() +
theme(
legend.position = "none",
) +
xlab("Name of genes") +
ylab("TMM Normalized counts")+
ggtitle("Saline treated female vs male")

Session info
sessionInfo()
## R version 4.3.0 (2023-04-21)
## Platform: aarch64-apple-darwin20 (64-bit)
## Running under: macOS 14.0
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## time zone: Australia/Melbourne
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] patchwork_1.1.3 kableExtra_1.3.4 hrbrthemes_0.8.0 lubridate_1.9.2
## [5] forcats_1.0.0 stringr_1.5.0 dplyr_1.1.2 purrr_1.0.2
## [9] readr_2.1.4 tidyr_1.3.0 tibble_3.2.1 ggplot2_3.4.3
## [13] tidyverse_2.0.0
##
## loaded via a namespace (and not attached):
## [1] gtable_0.3.3 xfun_0.40 bslib_0.5.1
## [4] tzdb_0.4.0 vctrs_0.6.3 tools_4.3.0
## [7] generics_0.1.3 curl_5.0.2 fansi_1.0.4
## [10] highr_0.10 pkgconfig_2.0.3 webshot_0.5.5
## [13] lifecycle_1.0.3 farver_2.1.1 compiler_4.3.0
## [16] munsell_0.5.0 httpuv_1.6.11 fontquiver_0.2.1
## [19] fontLiberation_0.1.0 htmltools_0.5.6 sass_0.4.7
## [22] yaml_2.3.7 Rttf2pt1_1.3.12 pillar_1.9.0
## [25] later_1.3.1 crayon_1.5.2 jquerylib_0.1.4
## [28] extrafontdb_1.0 gfonts_0.2.0 ellipsis_0.3.2
## [31] cachem_1.0.8 mime_0.12 fontBitstreamVera_0.1.1
## [34] tidyselect_1.2.0 rvest_1.0.3 digest_0.6.33
## [37] stringi_1.7.12 labeling_0.4.2 extrafont_0.19
## [40] fastmap_1.1.1 grid_4.3.0 colorspace_2.1-0
## [43] cli_3.6.1 magrittr_2.0.3 crul_1.4.0
## [46] utf8_1.2.3 withr_2.5.0 gdtools_0.3.3
## [49] scales_1.2.1 promises_1.2.1 timechange_0.2.0
## [52] rmarkdown_2.24 httr_1.4.7 hms_1.1.3
## [55] shiny_1.7.5 evaluate_0.21 knitr_1.43
## [58] viridisLite_0.4.2 rlang_1.1.1 Rcpp_1.0.11
## [61] xtable_1.8-4 glue_1.6.2 httpcode_0.3.0
## [64] xml2_1.3.5 svglite_2.1.1 rstudioapi_0.15.0
## [67] jsonlite_1.8.7 R6_2.5.1 systemfonts_1.0.4