Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Creating multiple plots in ggplot from a dataf rame with titles corresponding to the row names

$
0
0

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


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>