- I'm trying to make a split barplot with different colors for the x-axis labels. I want the x-axis labels (e.g. Vogesella) to show up as the correct color when they are plotted on the graph according to the host species.
- As you can see, none of the Vogesella x-axis labels are correct, and they are defaulting to black. I tried using vectorized input to element_text, but I get a warning saying that it isn't officially supported. Is there some workaround I can do to make this possible?
- Here is the code that I used to make the simplified barplot.
System Info:
platform x86_64-apple-darwin15.6.0
arch x86_64
os darwin15.6.0
system x86_64, darwin15.6.0
status
major 3
minor 6.3
year 2020
month 02
day 29
svn rev 77875
language R
version.string R version 3.6.3 (2020-02-29)
nickname Holding the Windsock
df %>%
ggplot( aes(x = genus, y = avg_rel_abund, fill = host_species))+
geom_bar(stat = "Identity") +
facet_grid(cols = vars(host_species), scales = "free") +
scale_fill_brewer(type = "qual", palette = 1) +
theme(axis.title.x = element_blank(),
axis.text.x = element_text(angle = 70, hjust = 1, size = 10,
color = df$color),
axis.title.y = element_text(size = 10),
axis.text.y = element_text(size = 10)) +
guides(fill = guide_legend(size = 10)) +
labs( y = "Relative Abundance (Genus)", title = "Day 3 Genera
Present in Host Phycospheres", fill = "Host Species") +
scale_y_continuous("Average Relative Abundance") +
scale_x_reordered()
Dataset:
df <- structure(list(genus = structure(c(3L, 1L, 4L, 2L, 5L), .Label = c("Vogesella___Coelastrum",
"Vogesella___Scenedesmus", "Vogesella___Chlorella", "Vogesella___Monoraphidium",
"Vogesella___Selenastrum"), class = "factor"), host_species = structure(c(1L,
2L, 4L, 3L, 5L), .Label = c("Chlorella", "Coelastrum", "Scenedesmus",
"Monoraphidium", "Selenastrum"), class = "factor"), avg_rel_abund = c(0.0476201763676562,
0.0723617033127999, 0.0254124767307784, 0.0615452700310325, 0.0124210779718639
), time = c("D3", "D3", "D3", "D3", "D3"), color = c("#7FC97F",
"#BEAED4", "black", "#FDC086", "#386CB0")), row.names = c(NA,
-5L), class = c("tbl_df", "tbl", "data.frame"))
agg_genus_data_D3_color
or use dput(agg_genus_data_D3_color). These links should be of help: minimal reproducible example and How to Ask – Peter