showing more than 6 values in a graph doesn't seem to work

88 views
Skip to first unread message

waschbaer

unread,
Feb 11, 2010, 12:25:58 AM2/11/10
to ggplot2
Hi @all

I am sorry to post another problem here but I came across the
following error message (see code below):

Error: scale_shape_discrete can deal with a maximum of 6 discrete
values, but you have 10. See ?scale_manual for a possible alternative

read.csv("http://dl.dropbox.com/u/4236038/
seasonal_var_gw_sixmile.csv") -> seasonal
melt_seasonal <- melt(seasonal, id=c("ID", "date"), na.rm=TRUE)
melt_seasonal$ID <- factor(melt_seasonal$ID, levels =
c(106,107,100,101,125,115,110,112,124,119))
ggplot(melt_seasonal, aes(x = date, y = value, group = ID)) +
geom_point(aes(shape = factor(ID))) + scale_shape(solid=FALSE) +
facet_grid(variable ~ . , scales = "free") + theme_bw() +
opts(legend.key=theme_rect(fill=NULL,colour="white")) +
scale_x_discrete(expand=c(.005,.005),
breaks=c("2008-10-26","2009-01-27","2009-03-16","2009-07-20","2009-11-16"),
labels=c("26 Oct","27 Jan","16 Mar","20 Jul","16 Nov"))

The only difference to a plot that was working is that this plot
should have 10 ID showing (compared to the one that was working and
had only 6 IDs showing up).

Any ideas what I have to change? It suggested to use scale_manual but
I tried it and it didn't work either.

Thanks
Martin

smu

unread,
Feb 11, 2010, 3:48:12 AM2/11/10
to waschbaer, ggplot2
Hi,


On Wed, Feb 10, 2010 at 09:25:58PM -0800, waschbaer wrote:
> Hi @all
>
> I am sorry to post another problem here but I came across the
> following error message (see code below):
>
> Error: scale_shape_discrete can deal with a maximum of 6 discrete
> values, but you have 10. See ?scale_manual for a possible alternative


> ...

btw. scale_shape(..) does not exists

>
> Any ideas what I have to change? It suggested to use scale_manual but
> I tried it and it didn't work either.
>

The message suggest to have a look at the help page of scale_manual,
which tells you show to specify colours. shapes etc. manually.

for example:

ggplot(melt_seasonal, aes(x = date, y = value, group = ID)) +
geom_point(aes(shape = factor(ID))) +

facet_grid(variable ~ . , scales = "free") +

scale_shape_manual("",values=c("106"= 1, "107"= 2, "100"= 3,
"101"= 4, "125"= 5, "115"= 6, "110"= 7, "112"= 8, "124"= 9, "119"= 10))


regards,
stefan

waschbaer

unread,
Feb 11, 2010, 4:29:14 AM2/11/10
to ggplot2
Hi Stefan

I tried your suggestion and it works in the way that at least it is
now plotting the graph. However, there are now two legends, one
showing the points only and the other one showing the lines only. Is
there a way to merge them?

Please have a look at the code:

read.csv("/Volumes/MARTIN_DATA/PhD/PhD/data/Stats/2010_01_new_stats/R/
first_run/seasonal_var_gw_sixmile.csv") -> seasonal
#to change labels for nutrients add the following code
names(seasonal)=c("ID","date","Nitrite-N","Nitrate-N","Ammonia-
N","organic N","Orthophosphate","total P")

melt_seasonal <- melt(seasonal, id=c("ID", "date"), na.rm=TRUE)

ggplot(melt_seasonal, aes(x = date, y = value, group = ID)) +

geom_line(aes(color=factor(ID))) + geom_point(aes(shape = factor(ID)))
+ scale_shape(solid=FALSE) + facet_grid(variable ~ . , scales =


"free") + theme_bw() +

opts(legend.key=theme_rect(fill=NULL,colour="white")) +


scale_shape_manual("",values=c("106"= 1, "107"= 2, "100"= 3, "101"= 4,

"125"= 5, "115"= 6, "110"= 7, "112"= 8, "124"= 9, "119"= 10)) +


scale_x_discrete(expand=c(.005,.005),
breaks=c("2008-10-26","2009-01-27","2009-03-16","2009-07-20","2009-11-16"),
labels=c("26 Oct","27 Jan","16 Mar","20 Jul","16 Nov"))

smu

unread,
Feb 11, 2010, 8:01:17 AM2/11/10
to waschbaer, ggplot2
Hi,

On Thu, Feb 11, 2010 at 01:29:14AM -0800, waschbaer wrote:
>
> I tried your suggestion and it works in the way that at least it is
> now plotting the graph. However, there are now two legends, one
> showing the points only and the other one showing the lines only. Is
> there a way to merge them?
>

for me it worked when i specified the colour scale manually too:

ggplot(melt_seasonal, aes(x = date, y = value, group = ID,
colour=factor(ID),shape=factor(ID))) +
geom_line() + geom_point() +


facet_grid(variable ~ . , scales ="free") +
scale_shape_manual("",values=c("106"= 1, "107"= 2, "100"= 3, "101"= 4,

"125"= 5, "115"= 6, "110"= 7, "112"= 8, "124"= 9, "119"= 10)) +
scale_x_discrete(expand=c(.005,.005),
breaks=c("2008-10-26","2009-01-27","2009-03-16","2009-07-20","2009-11-16"),

labels=c("26 Oct","27 Jan","16 Mar","20 Jul","16 Nov")) +
scale_colour_manual("",values=c("106"= 1, "107"= 2, "100"= 3, "101"= 4,


"125"= 5, "115"= 6, "110"= 7, "112"= 8, "124"= 9, "119"= 10))


But i don't know if this is the only solution. I though the same legend
title would merge the two legends, but simply using
+ scale_colour_discrete("") had not effect.

regards,
stefan

waschbaer

unread,
Feb 11, 2010, 7:22:33 PM2/11/10
to ggplot2
Hi Stefan

That worked for me as well. Cheers.

Reply all
Reply to author
Forward
0 new messages