geom_vline with facets

309 views
Skip to first unread message

Nikola Knežević

unread,
Apr 28, 2011, 1:53:28 PM4/28/11
to ggp...@googlegroups.com
Hi,

I want to make a 2x2 faceted graph, where each facet has its own vline. If I try something like this:

TET.m <- data.frame(platform=levels(data$platform),vl=c(24.5,38.8))
TET.r <- data.frame(platform=levels(data$platform),vl=c(39.7,59.8))

ggplot(data=data) +
geom_vline(aes(xintercept=vl,type='model'), data=TET.m) +
geom_vline(aes(xintercept=vl,type='real'), data=TET.r) +
geom_line(size=0.4, aes(x=texec,y=throughput,linetype=proto)) +
facet_grid(type~platform, labeller=label.cluster)

I get a 2x4 graph (2 columns, 4 rows), where rows are 1, 2, model, and real. If I make a single TET data.frame, with type column, I again get the same thing.

What am I doing wrong? :)

Thanks,
Nikola

Brandon Hurr

unread,
Apr 28, 2011, 2:28:40 PM4/28/11
to Nikola Knežević, ggp...@googlegroups.com
Can you supply the rest of the data? Hard to make heads or tails of what's happening.

Seems like Type has 4 factor levels in your dataframe. Whether you intend that to happen or not, ggplot is just doing what you tell it to. 

Brandon

2011/4/28 Nikola Knežević <laladel...@gmail.com>

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Nikola Knežević

unread,
Apr 30, 2011, 6:01:08 PM4/30/11
to ggp...@googlegroups.com
Hi,

sorry about that. The data is attached.

I managed to go around this problem (I'm a novice in R:(), doing this:
nda <- data
nda$texec<-NULL
nda$proto<-NULL
TET <- recast(nda,platform+type~.,mean)
TET$vl <- c(44.921875,59.8,34.27734375,39.7)

ggplot(data=data) +
geom_point(aes(x=texec,y=throughput,shape=proto), size=1.5) +
geom_line(size=0.4, aes(x=texec,y=throughput,linetype=proto)) +
facet_grid(type~platform, labeller=label.cluster) +
geom_vline(aes(xintercept=vl), data=TET)

label.cluster <- function(variable, value) {
if (variable == 'platform') {
levels(value)[which(levels(value) == 'emulab')] <- 'Emulab'
levels(value)[which(levels(value) == 'g5k')] <- 'Grid 5000'
}
return(value)
}

my_y_label <- function(x, ...) {
format(x/1000, big.mark=TRUE, scientific=FALSE, ...)
}


On 28 Apr 2011, at 20:28 , Brandon Hurr wrote:

> Can you supply the rest of the data? Hard to make heads or tails of what's
> happening.
>
> Seems like Type has 4 factor levels in your dataframe. Whether you intend
> that to happen or not, ggplot is just doing what you tell it to.

>> I want to make a 2x2 faceted graph, where each facet has its own vline. If

data.txt
Reply all
Reply to author
Forward
0 new messages