Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Combine multiple plot in loop color each plot by different column in dataframe

I am trying combine the multiple plots according to on of the thread here my problem is I want to separate based on coloured plot with different values can any one help me what I am missing, (Note: my original data i have some 30 column values)

data(iris)
list_data=c("Petal.Length", "Petal.Width")
# Make plots.
plot_list = list()
for (i in list_data) {
  p = ggplot(iris, aes(y=Sepal.Length, x=Sepal.Width)) +
    geom_point(size=3, aes(colour=i))
  plot_list[[i]] = p
}

pdf("plots.pdf")
for (i in list_data) {
  print(plot_list[[i]])
}

dev.off()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

We may use .data[[i]] in colour

for (i in list_data) {
  p = ggplot(iris, aes(y=Sepal.Length, x=Sepal.Width)) +
    geom_point(size=3, aes(colour=.data[[i]]))
  plot_list[[i]] = p
}

-output

> plot_list[[1]]

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading