R ggplot2 shape-changing (melt function) optionally graphic data sets

I use ggplot to plot on multiple datasets, however I would like to build them so that each dataset has its own geom_line function geom_line that I can split the lines and hide them if necessary.

  ggplot(MeanFrameMelt, aes(x=variable, y=value, color=Legend, group=Legend)) + geom_line() 

Input table after conversion with melt function in reseape package:

 Legend variable value table_A.txt V1 0.008927491 table_B.txt V1 0.009080929 table_C.txt V1 0.008513332 table_D.txt V1 0.008337751 table_A.txt V2 0.008957742 table_B.txt V2 0.009100265 table_C.txt V2 0.008508966 

table A must be one geom_line (line on the graph) of table B a second geom_line , etc. Is it possible or do I need to go back and change the melting of the previous data frame?

Edit: ok this is a melt function:

 library(plyr) library(reshape) MeanFrameMelt <- melt(MeanFrame2, id.vars="Legend") 

The data that I gave you has only two points for each row, so imagine that you have hundreds of points from each table (A, B, C and D), so there will be four rows in this graph. I want to be able to disable each row using a check box, but for this I need to have a unique identifier for each row that will allow me to do this. So I was thinking about making a separate + geom_line(for table A) + geom_line(for table B) + geom_line(for table C)...

Hope this clarifies a bit.

Edit2: this is how the graph now looks, and it should look the same after that, but with 4 geom_line calls instead of the one that it has:

enter image description here

+4
source share
1 answer

I think this is close to what you want:

 ggplot(MeanFrameMelt, aes(x=variable, y=value, color=Legend, group=Legend))+ geom_line(aes(linetype=Legend)) 

Edit After clarification OP

With ggplot2 (Lattice also) you can combine data sources and subsets for each layer

Here, for example, I want to show only 2 lines

 library(ggplot2) ggplot(dat, aes(x=variable, y=value, , color=Legend, group=Legend))+ geom_line(subset= .(Legend %in% c('table_A.txt','table_D.txt'))) 

enter image description here

You can bind your flag to the list of displayed string.

  geom_line(subset= .(Legend %in% visibleCheckedList)) 
0
source

All Articles