0

I would like, with this data set: https://dl.dropboxusercontent.com/u/73950/mydata.csv , to display 4 different graphics: GA, N1, N2, PE in different shades. For each graphic, all values of category "m" must be displayed on the y axis, with "nbr" on the x axis.

Here's the code I have so far (thanks to @CMichael for most of this code)

require(reshape2)

mydata = read.csv(file="/Users/Rodolphe/Downloads/mydata.csv", sep=";", header=TRUE)
dataM = melt(mydata,c("nbr"))

#parse labels to identify vertical category and fill the value correspondingly
dataM$order = ifelse(grepl("GED",dataM$variable),"GED",ifelse(grepl("RAN",dataM$variable),"RAN",ifelse(grepl("EIG",dataM$variable),"EIG","BET")))
#parse labels to identify horizontal category and fill the value correspondingly
dataM$net = ifelse(grepl("PE",dataM$variable),"PE",ifelse(grepl("GA",dataM$variable),"GA",ifelse(grepl("N1",dataM$variable),"N1","N2")))
#parse label to identify category
dataM$category = ifelse(grepl("mNC",dataM$variable),"mNC",ifelse(grepl("aSPL",dataM$variable),"aSPL",ifelse(grepl("d",dataM$variable),"d","m")))


ggplot(dataM[dataM$category=="m" & dataM$order=="RAN",], aes(value, fill=net)) + geom_density(alpha = .3, color=NA)  + scale_fill_brewer(palette="Set1")

Which gives me:

enter image description here

That's, aesthetically, exactly what I need. The display is obviously wrong, however, and several things confuse me. For one thing, I can't seem to force "nbr" on the x axis. Am I on the right track at all with this code?

4
  • Looking at your dataset, I'm not sure what the problem is. nbr looks like a case ID, or sample number, or some such. Why would you want to plot it on the x-axis? In your data, GA, N1, N2, and PE have values on [0,10], and you are plotting the density functions of those values. Commented Jan 11, 2014 at 17:09
  • How is it obviously wrong? Commented Jan 11, 2014 at 17:13
  • @jlhoward : It is actually quite like a time series, where nbr would act as "t" would in an actual time series. But I think I understand what you mean: I'm filling under the curves in order to better distinguish them, but they aren't density at all. I'm doing something wrong... Commented Jan 11, 2014 at 17:16
  • @rawr I just realized it's not a density plot that I need, but a regular plot that would be filled by a colour, in order to distinguish the "net" I'm plotting Commented Jan 11, 2014 at 17:19

2 Answers 2

1

So based on OP's comments, this might be one way to plot the data:

ggplot(dataM[dataM$category=="m" & dataM$order=="RAN",], aes(x=nbr, y=value, fill=net)) + 
  geom_ribbon(aes(ymin=0, ymax=value),alpha=0.3)+ 
  scale_fill_brewer(palette="Set1")

Or, IMHO a better option:

ggplot(dataM[dataM$category=="m" & dataM$order=="RAN",], aes(x=nbr, y=value, fill=net)) + 
  geom_line(aes(color=net))+
  geom_ribbon(aes(ymin=0, ymax=value),alpha=0.3)+ 
  scale_fill_brewer(palette="Set1")+
  facet_grid(net~.)

Sign up to request clarification or add additional context in comments.

Comments

0

based on OP's comments, this might be one way to plot the data:

ggplot(dataM[dataM$category=="m" & dataM$order=="RAN",], aes(x=nbr, y=value, fill=net)) + 
  geom_ribbon(aes(ymin=0, ymax=value),alpha=0.3)+ 
  scale_fill_brewer(palette="Set1")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.