Domanda

How to plot in R like this(same as the graphs) ? Could you please post the R code in your answer?

I am a R beginner and I find it is difficult to plot in R for me.

Thank you !

È stato utile?

Soluzione

The bottom graph is called a "parallel coordinates plot". You can do a quick Google search to find several ways of doing this in R. Here are two, both using the "iris" dataset.

  1. ggplot2

    With this approach, you basically say which columns have the data you want to plot, and specify your grouping variable using geom_line().

    library(ggplot2)
    p <- ggpcp(iris, vars = names(iris[1:4]))
    p + geom_line(aes(color = Species))
    

    enter image description here

  2. MASS

    The approach here is similar. First specify your data, then specify how your data are grouped (in the case of the "iris" dataset, there are three species, with 50 observations each).

    library(MASS)
    parcoord(iris[-5], col = rep(1:3, each = 50))
    

    enter image description here

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top