0
votes

I am using the ggparcoord() function of the GGally package in R to create a Parallel Coordinate Plot of the iris data (Present in R). I used the following code

ggparcoord(data=iris, columns=1:4 , groupColumn=5,alpha=I(0.3))+theme_light()+theme(legend.position="none") .

Now I have calculated median of the four variables (Sepal.Length, Sepal.Width, Petal.Length, Petal.Width) separately for the three species (setosa,versicolor,virginica) and using this information I have created a new data.

Here is the data (I have named the data as med)

  |Sepal.Length|    Sepal.Width |Petal.Length | Petal.Width | Species
-----------------------------------------------------------------
  |         5   |         3.4   |      1.5    |    0.2      |  1
  |        5.9  |         2.8   |     4.35    |    1.3      |  2
  |        6.5  |         3     |     5.55    |      2      |  3        

Here 1 denotes setosa, 2 denotes versicolor and 3 denotes virginica. Using this data I have again created a Parallel coordinate plot. The code is:

ggparcoord(data=med,columns=1:4, groupColumn=5)+theme_light() .

I now wish to superimpose this plot over the previous plot. To do so I tried using

p<-ggparcoord(data=iris, columns=1:4 , groupColumn=5,alpha=I(0.3)) p+ggparcoord(data=med,columns=1:4, groupColumn=5)+theme_light() .

But this gives me an error of the following type

"Error: Don't know how to add o to a plot".

Please help me resolve this problem.

Thank You in advance for taking out time to look at my question.

Souradeep

1

1 Answers

0
votes

In this case you need to create a dataset that combines both your summary information and the raw data. I use dplyr to create the summary by species, give it an alpha value, then bind it back with the original iris dataset with an added alpha value.

The resultant plot shows the raw data as very transparent, and the summarized median as non-transparent. You can adjust this for linetype, color, etc.

library(dplyr)
library(GGally)
library(ggplot2)

med <- iris %>% 
  group_by(Species) %>% 
  summarise_each(funs(median)) %>% 
  mutate(alpha = 1) %>% 
  bind_rows(mutate(iris, alpha = 0.1))

ggparcoord(data = med, columns = 2:4 , groupColumn = 1, alpha = "alpha") + 
  theme_light() + 
  theme(legend.position="none") 

enter image description here