Arranging y-axis in geom_tile

So I'm trying to reorder my y-axis of my heatmap with geom_tile.

> dput(dat.light)
structure(list(title = c("LHCB ( 19 )", "LHCB ( 19 )", "LHCB ( 19 )", 
"LHCB ( 19 )", "LHCB ( 19 )", "Phototropin ( 1 )", "Phototropin ( 1 )", 
"Phototropin ( 1 )", "Phototropin ( 1 )", "Phototropin ( 1 )", 
"ELIP ( 1 )", "ELIP ( 1 )", "ELIP ( 1 )", "ELIP ( 1 )", "ELIP ( 1 )", 
"FLU ( 1 )", "FLU ( 1 )", "FLU ( 1 )", "FLU ( 1 )", "FLU ( 1 )", 
"LTD ( 1 )", "LTD ( 1 )", "LTD ( 1 )", "LTD ( 1 )", "LTD ( 1 )", 
"XCT ( 1 )", "XCT ( 1 )", "XCT ( 1 )", "XCT ( 1 )", "XCT ( 1 )", 
"NOL ( 1 )", "NOL ( 1 )", "NOL ( 1 )", "NOL ( 1 )", "NOL ( 1 )", 
"PAO ( 2 )", "PAO ( 2 )", "PAO ( 2 )", "PAO ( 2 )", "PAO ( 2 )", 
"THF ( 1 )", "THF ( 1 )", "THF ( 1 )", "THF ( 1 )", "THF ( 1 )", 
"DVR ( 1 )", "DVR ( 1 )", "DVR ( 1 )", "DVR ( 1 )", "DVR ( 1 )", 
"GLUTRBP ( 2 )", "GLUTRBP ( 2 )", "GLUTRBP ( 2 )", "GLUTRBP ( 2 )", 
"GLUTRBP ( 2 )", "CHLM ( 1 )", "CHLM ( 1 )", "CHLM ( 1 )", "CHLM ( 1 )", 
"CHLM ( 1 )", "CHLI ( 1 )", "CHLI ( 1 )", "CHLI ( 1 )", "CHLI ( 1 )", 
"CHLI ( 1 )", "POR ( 1 )", "POR ( 1 )", "POR ( 1 )", "POR ( 1 )", 
"POR ( 1 )", "PPOX2 ( 1 )", "PPOX2 ( 1 )", "PPOX2 ( 1 )", "PPOX2 ( 1 )", 
"PPOX2 ( 1 )", "PSA ( 1 )", "PSA ( 1 )", "PSA ( 1 )", "PSA ( 1 )", 
"PSA ( 1 )", "TAB2 ( 1 )", "TAB2 ( 1 )", "TAB2 ( 1 )", "TAB2 ( 1 )", 
"TAB2 ( 1 )", "Y3IP1 ( 1 )", "Y3IP1 ( 1 )", "Y3IP1 ( 1 )", "Y3IP1 ( 1 )", 
"Y3IP1 ( 1 )", "PSI ( 6 )", "PSI ( 6 )", "PSI ( 6 )", "PSI ( 6 )", 
"PSI ( 6 )", "PSIIA ( 1 )", "PSIIA ( 1 )", "PSIIA ( 1 )", "PSIIA ( 1 )", 
"PSIIA ( 1 )", "PSII ( 4 )", "PSII ( 4 )", "PSII ( 4 )", "PSII ( 4 )", 
"PSII ( 4 )", "HCF ( 4 )", "HCF ( 4 )", "HCF ( 4 )", "HCF ( 4 )", 
"HCF ( 4 )", "LPA ( 2 )", "LPA ( 2 )", "LPA ( 2 )", "LPA ( 2 )", 
"LPA ( 2 )", "PSIIR ( 2 )", "PSIIR ( 2 )", "PSIIR ( 2 )", "PSIIR ( 2 )", 
"PSIIR ( 2 )", "MET1 ( 2 )", "MET1 ( 2 )", "MET1 ( 2 )", "MET1 ( 2 )", 
"MET1 ( 2 )", "CTPA3 ( 1 )", "CTPA3 ( 1 )", "CTPA3 ( 1 )", "CTPA3 ( 1 )", 
"CTPA3 ( 1 )", "B6-F ( 1 )", "B6-F ( 1 )", "B6-F ( 1 )", "B6-F ( 1 )", 
"B6-F ( 1 )", "TRXM ( 2 )", "TRXM ( 2 )", "TRXM ( 2 )", "TRXM ( 2 )", 
"TRXM ( 2 )", "PGR ( 1 )", "PGR ( 1 )", "PGR ( 1 )", "PGR ( 1 )", 
"PGR ( 1 )", "Plastocyanin ( 1 )", "Plastocyanin ( 1 )", "Plastocyanin ( 1 )", 
"Plastocyanin ( 1 )", "Plastocyanin ( 1 )", "Ferredoxin ( 4 )", 
"Ferredoxin ( 4 )", "Ferredoxin ( 4 )", "Ferredoxin ( 4 )", "Ferredoxin ( 4 )", 
"OEC ( 5 )", "OEC ( 5 )", "OEC ( 5 )", "OEC ( 5 )", "OEC ( 5 )", 
"PNSB3 ( 1 )", "PNSB3 ( 1 )", "PNSB3 ( 1 )", "PNSB3 ( 1 )", "PNSB3 ( 1 )"
), Role = c("Light-Harvesting Complex", "Light-Harvesting Complex", 
"Light-Harvesting Complex", "Light-Harvesting Complex", "Light-Harvesting Complex", 
"Light sensor", "Light sensor", "Light sensor", "Light sensor", 
"Light sensor", "Regulation of chlorophyll synthesis/photoprotection/response to light", 
"Regulation of chlorophyll synthesis/photoprotection/response to light", 
"Regulation of chlorophyll synthesis/photoprotection/response to light", 
"Regulation of chlorophyll synthesis/photoprotection/response to light", 
"Regulation of chlorophyll synthesis/photoprotection/response to light", 
"Chlorophyll synthesis regulation", "Chlorophyll synthesis regulation", 
"Chlorophyll synthesis regulation", "Chlorophyll synthesis regulation", 
"Chlorophyll synthesis regulation", "Light-Harvesting Complex", 
"Light-Harvesting Complex", "Light-Harvesting Complex", "Light-Harvesting Complex", 
"Light-Harvesting Complex", "Light harvesting circadian rhythm", 
"Light harvesting circadian rhythm", "Light harvesting circadian rhythm", 
"Light harvesting circadian rhythm", "Light harvesting circadian rhythm", 
"Chlorophyll degradation/catabolism", "Chlorophyll degradation/catabolism", 
"Chlorophyll degradation/catabolism", "Chlorophyll degradation/catabolism", 
"Chlorophyll degradation/catabolism", "Chlorophyll degradation/catabolism", 
"Chlorophyll degradation/catabolism", "Chlorophyll degradation/catabolism", 
"Chlorophyll degradation/catabolism", "Chlorophyll degradation/catabolism", 
"PSII Assembly ; Chlorophyll degradation", "PSII Assembly ; Chlorophyll degradation", 
"PSII Assembly ; Chlorophyll degradation", "PSII Assembly ; Chlorophyll degradation", 
"PSII Assembly ; Chlorophyll degradation", "Chlorophyll synthesis", 
"Chlorophyll synthesis", "Chlorophyll synthesis", "Chlorophyll synthesis", 
"Chlorophyll synthesis", "Chlorophyll synthesis", "Chlorophyll synthesis", 
"Chlorophyll synthesis", "Chlorophyll synthesis", "Chlorophyll synthesis", 
"Chlorophyll synthesis", "Chlorophyll synthesis", "Chlorophyll synthesis", 
"Chlorophyll synthesis", "Chlorophyll synthesis", "Chlorophyll synthesis", 
"Chlorophyll synthesis", "Chlorophyll synthesis", "Chlorophyll synthesis", 
"Chlorophyll synthesis", "Chlorophyll synthesis", "Chlorophyll synthesis", 
"Chlorophyll synthesis", "Chlorophyll synthesis", "Chlorophyll synthesis", 
"Chlorophyll synthesis", "Chlorophyll synthesis", "Chlorophyll synthesis", 
"Chlorophyll synthesis", "Chlorophyll synthesis", "PSI Assembly", 
"PSI Assembly", "PSI Assembly", "PSI Assembly", "PSI Assembly", 
"PSI Assembly", "PSI Assembly", "PSI Assembly", "PSI Assembly", 
"PSI Assembly", "PSI Assembly", "PSI Assembly", "PSI Assembly", 
"PSI Assembly", "PSI Assembly", "PSI ; photosynthesis", "PSI ; photosynthesis", 
"PSI ; photosynthesis", "PSI ; photosynthesis", "PSI ; photosynthesis", 
"PSII Assembly / oxygen evolving complex", "PSII Assembly / oxygen evolving complex", 
"PSII Assembly / oxygen evolving complex", "PSII Assembly / oxygen evolving complex", 
"PSII Assembly / oxygen evolving complex", "PSII ; photoinhibition ; cell redox homeostasis", 
"PSII ; photoinhibition ; cell redox homeostasis", "PSII ; photoinhibition ; cell redox homeostasis", 
"PSII ; photoinhibition ; cell redox homeostasis", "PSII ; photoinhibition ; cell redox homeostasis", 
"PSII Assembly", "PSII Assembly", "PSII Assembly", "PSII Assembly", 
"PSII Assembly", "PSII Assembly", "PSII Assembly", "PSII Assembly", 
"PSII Assembly", "PSII Assembly", "PSII Assembly/Repair", "PSII Assembly/Repair", 
"PSII Assembly/Repair", "PSII Assembly/Repair", "PSII Assembly/Repair", 
"PSII Assembly/Repair", "PSII Assembly/Repair", "PSII Assembly/Repair", 
"PSII Assembly/Repair", "PSII Assembly/Repair", "PSII processing", 
"PSII processing", "PSII processing", "PSII processing", "PSII processing", 
"Photosynthetic ETC", "Photosynthetic ETC", "Photosynthetic ETC", 
"Photosynthetic ETC", "Photosynthetic ETC", "ETC", "ETC", "ETC", 
"ETC", "ETC", "Photosynthetic ETC", "Photosynthetic ETC", "Photosynthetic ETC", 
"Photosynthetic ETC", "Photosynthetic ETC", "Photosynthetic ETC", 
"Photosynthetic ETC", "Photosynthetic ETC", "Photosynthetic ETC", 
"Photosynthetic ETC", "Photosynthetic ETC", "Photosynthetic ETC", 
"Photosynthetic ETC", "Photosynthetic ETC", "Photosynthetic ETC", 
"PSII assembly/stability; photosynthetic ETC", "PSII assembly/stability; photosynthetic ETC", 
"PSII assembly/stability; photosynthetic ETC", "PSII assembly/stability; photosynthetic ETC", 
"PSII assembly/stability; photosynthetic ETC", "Photosynthetic ETC", 
"Photosynthetic ETC", "Photosynthetic ETC", "Photosynthetic ETC", 
"Photosynthetic ETC"), sample = c("Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day", "Initial biomass", "UT_24 hr", 
"UT_28 day", "CA_24 hr", "CA_28 day"), value = c(-0.00148421052631579, 
0.11413947368421, 0.548157894736842, 0.231607894736842, 0.0399526315789474, 
-0.0046, 0.03245, 1.52205, -0.3316, 0.19455, -0.0016, 0.13825, 
0.0977, 0.32005, -0.0115, 0.0021, 0.04695, 0.9752, 0.218, 0.44905, 
-0.00815, -0.0016, -1.13405, -0.0585, -0.38015, 0.0054, 0.0747, 
-0.14525, -0.26955, 0.2849, 0.0058, 0.26805, 0.4136, 0.4194, 
0.48645, 0.00155, 1.32415, -0.28115, -0.174, -0.090725, 0.01315, 
-0.21535, 0.77295, 0.35035, 0.20675, -0.00635, 0.00425, 1.66895, 
-0.26885, 0.3558, 0.002275, -0.125, 0.66195, -0.03715, 0.639825, 
0.06195, -0.7026, 0.70335, 0.0508, 0.2034, 0.0035, -0.08745, 
1.16065, -0.1873, 0.3278, 0.00625, -0.15245, 1.04235, -0.156, 
0.5354, 0.00615, -0.2967, 0.44175, -0.2197, -0.16085, -0.0068, 
-0.06605, 0.79715, -0.09575, 0.0478, 0.0018, 0.13885, 1.54235, 
0.08795, 0.4481, 0.0029, 0.5019, -0.19885, 0.23115, 0.0657, 0.01125, 
-0.32715, -0.992616666666667, 0.286158333333333, -0.923008333333333, 
0.0099, 0.15655, 0.8325, 0.26235, 0.98185, 0.0017125, -0.1559625, 
-0.9936125, 0.090975, -0.898175, 0.0085, -0.0874625, 0.4838625, 
0.0676125, 0.4408625, -6e-04, -0.076875, 0.862475, -0.03565, 
0.2728, 0.0045, 0.23595, -1.2012, 0.217825, -0.700025, -0.000275000000000001, 
0.0979, -0.87695, -0.227325, -0.424975, -0.00215, -0.2825, 0.67605, 
-0.25575, 0.358, -0.0011, 0.74615, -0.00505, 0.1954, -0.2991, 
0.0074, 0.270175, -0.1304, 0.102075, 0.216125, 0.000450000000000001, 
0.20435, 0.02425, 0.22675, -0.35665, 0.00235, 0.0758, -1.50505, 
-0.24065, -1.0019, 0.0030125, -0.2603875, -0.983375, -0.177025, 
-0.701575, 0.000430000000000001, -0.67105, -1.11846, -0.14863, 
-0.52783, 0.0056, -0.0333, -0.9034, -0.0314, -0.74885)), class = c("tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -165L))

I created level orders and tried to arrange the x and y-axis by these level orders, and it worked when I did it for the x-axis, but when I did it for the y-axis it just combines everything into one row and overlaps all the numbers.

level_order<-c("Initial biomass","UT_24 hr","UT_28 day","CA_24 hr","CA_28 day")
light_level_order<-c("PSIIA (1)","PSII (4)","HCF (4)","LPA (2)","PSIIR (2)","MET1 (2)",
                     "CTPA3 (1)","PSA (1)","TAB2 (1)","Y3IP1 (1)","PSI (6)","B6-F (1)",
                     "TRXM (2)","PGR (1)","Plastocyanin (1)","Ferredoxin (4)",
                     "OEC (5)","PNSB3 (1)","LHCB (19)","Phototropin (1)","ELIP (1)",
                     "FLU (1)","LTD (1)","XCT (1)","NOL (1)","PAO (2)","THF (1)","DVR (1)",
                     "GLUTRBP (2)","CHLM (1)","CHLI (1)","POR (1)","PPOX2 (1)","RuBisCO-A (3)",
                     "CA (2)")

plot_light<-ggplot(dat.light, aes(x = factor(sample,level=level_order), y=factor(title,level=light_level_order),fill=value)) +
  geom_tile(color = "black")+
  scale_fill_gradient2(limits=c(-2,2),low = "red",
                       mid = "white",
                       high = "cyan4")+
  # coord_fixed(ratio=0.2)+
  guides(fill=guide_colourbar(title='Log2 \nFold Change'))+
  theme(text=element_text(size=18),axis.text=element_text(size=16),axis.text.x=element_text(angle=90,vjust=0.5),axis.title=element_blank(),plot.title=element_text(size=18,hjust=0.5))+
  geom_text(aes(label=round(value,1)))

plot_light

It looks like the values in dat.light$title have a space before and after the number in parentheses (i.e. LHCB ( 19 )), but those in light_level_order do not. You can either add spaces in light_level_order or remove them in title (which I did below).

library(tidyverse)

dat.light = dat.light %>%
  mutate(title = str_replace(title, '\\( ', '\\('), 
         title = str_replace(title, ' \\)', '\\)'))

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.