1

I am trying to create multiple scatter plot graphs in ggplot that have the same structure but I want to have the respective name of the rows in the column. I need them to be separate (and therefore not use facet_wrap) because in a later step I use grid_arrange to arrange different combinations of the graphs onto a single layout.

ggplot(data = check1, mapping = aes(x = log10(conc), y = data, color = Sample.Data.Type)) +
labs(x = "Concentration (Log(uM))", y = "Response (%)") +
theme(legend.text = element_text(size = 12), legend.title = element_blank())+
ggtitle(ptitle) + 
geom_line(aes(linetype = Sample.Data.Type)) 
geom_point()

Because of this, I need to separate names for each plot that reflect the different row name being plotted. Below is sample code, I tried to pull all the row names in a separate vector and tried to paste on the respective graphs. But It is pulling random row names and pasting it in the graph.

loop.list <- c(d3$Name)
for (Name in loop.list) {
col <- grep( paste0("Chemical", Name), colnames(d3) )
ptitle <- paste0("Chemical", Name)
}

Is there any simple way to just add the rowname as the plot title, for which it is being plot? I am pretty new to R, so any help would be highly appreciated. Thanks

sk2020
  • 11
  • 2
  • Can you post a sample of your data? – novica Jan 29 '20 at 21:30
  • Without the data it is difficult to make suggestions but it seems there is a pretty comprehensive solution here: https://stackoverflow.com/questions/52434628/creating-multiple-ggplots-with-dplyr – novica Jan 29 '20 at 21:46
  • Hi Novica, Thanks for the suggestion. It worked :) – sk2020 Feb 04 '20 at 16:35

0 Answers0