geom_pointrange and position argument

3,335 views
Skip to first unread message

smu

unread,
Oct 11, 2009, 10:08:55 AM10/11/09
to ggp...@googlegroups.com
Hey,

i want to plot some data with discrete x-axis and continuous y-axis.
For each break on the x-axis, 4 different y values exists.

With position="identity" the points or pointranges overlap each other,
so i tried "dodge" and "jitter".

I don't see any changes with "dodge" and with "jitter" for some points
it's a bit difficult to identify the belonging x-axis breaks.

Any ideas how to move the ponts a little bit to the left and the right
(the best would be a fixed amount for each variable level, see example
below).

I can't use facets, because I use it allready, the example below is just
the data for one facet.

example:

library(ggplot2)
d = structure(list(Bundesland = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Eisenstadt (BGL)",
"Graz (STM)", "Klagenfurt (KTN)", "Kremsmünster (OOE)", "Salzburg (SBG)",
"St. Pölten (NOE)"), class = "factor"), variable = c("CLM_A1B",
"CLM_B1", "CLM_A1B", "CLM_B1", "CLM_A1B", "CLM_B1", "CLM_A1B",
"CLM_B1", "Remo_A1B", "Remo_B1", "Remo_A1B", "Remo_B1", "Remo_A1B",
"Remo_B1", "Remo_A1B", "Remo_B1"), Dekade = structure(c(1L, 1L,
2L, 2L, 3L, 3L, 4L, 4L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L), .Label = c("1961-2000",
"2001-2030", "2031-2070", "2071-2100"), class = "factor"), SRES = structure(c(1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("A1B",
"B1"), class = "factor"), mean = c(11.3087444999722, 11.3087444999722,
11.7518043639496, 11.8533944409593, 12.3789610591686, 12.229776183631,
13.1621765239205, 12.7607377942529, 13.0388901869159, 13.0388901869159,
13.610393167902, 13.5922494360296, 14.4502453271028, 14.1906542056075,
15.6681931464174, 15.178800623053), sd = c(0.558445359072224,
0.558445359072224, 0.643855367030372, 0.580734781470385, 0.736930693104638,
0.649717330030318, 0.666825505243008, 0.689166881171515, 0.649813010593805,
0.649813010593805, 0.598086022592438, 0.530013751143853, 0.802553323052953,
0.474180312808992, 0.682137990645673, 0.705061505200587)), .Names = c("Bundesland",
"variable", "Dekade", "SRES", "mean", "sd"
), row.names = c(NA, 16L), class = "data.frame")


ggplot(d) + geom_pointrange(aes(x=Dekade,y=mean,colour=variable,
ymin=mean-sd,ymax=mean+sd),position="jitter")

thanks for your help.

stefan

Andreas Christoffersen

unread,
Oct 13, 2009, 9:13:23 AM10/13/09
to ggp...@googlegroups.com
I have never worked with timeseries. But maybe it would be a good idea
to convert the x axit to a timeseries? - then maybe you could spread
out the decade observations with a month or so?

This is just an idea from a very novice R and ggplot2 user - I
apologize if I misunderstood your question.

James Howison

unread,
Oct 13, 2009, 9:42:21 AM10/13/09
to ggplot2
position_dodge with a fixed width seems to work:

ggplot(d) + geom_pointrange(aes(x=Dekade,y=mean,colour=variable,
ymin=mean-sd,ymax=mean+sd), position=position_dodge(width=1))

You might be able to turn each Dekade into sort of a grouped channel
by adding a transparent geom_hline() that covers all four, should be
something like +geom_hline(xintercept=Dekade, alpha=0.3, size=20)

or xintercept=1:4

but I can't get that to work for me (and R is dying trying to update
ggplot2 to 0.8.3)

--J

smu

unread,
Oct 13, 2009, 12:14:53 PM10/13/09
to ggplot2
hey,

* James Howison <ja...@freelancepropaganda.com>:
>
> position_dodge with a fixed width seems to work:
>
>
> ggplot(d) + geom_pointrange(aes(x=Dekade,y=mean,colour=variable,
> ymin=mean-sd,ymax=mean+sd), position=position_dodge(width=1))

thanks, thats perfekt, I didn't knew the width argument.

regards,
stefan
Reply all
Reply to author
Forward
0 new messages