legend of continuous variable as categorical variable

40 views
Skip to first unread message

Agustin Lobo

unread,
Sep 19, 2012, 7:33:38 AM9/19/12
to ggp...@googlegroups.com
Hi!

Using
http://dl.dropbox.com/u/3180464/vthcal2MIDAScal2m.rda

I'm doing:
qplot(DN,fill=glass,alpha=I(0.2),group=glass,data=vthcal2MIDAScal2m,geom=c("density"))+facet_grid(Image~.)+opts(title="Set
2")
qplot(DN,fill=temperature,alpha=I(0.2),group=temperature,data=vthcal2MIDAScal2m,geom=c("density"))+facet_grid(Image~.)+opts(title="Set
2")

actually, each histogram of DNs corresponds to a glass with a unique
temperature, so I would like the second qplot() but having
the actual temperatures of the 6 glasses in the legend. I think the
legend gets as it is because temperature is a continuous variable.
Is there any way I can set the values of the legend in the second plot
to match the ones of the glasses? (c(13.0,15.3,17.9,18.9,19.6,22.4)) ?

Thanks
Agus

David Johnston

unread,
Sep 19, 2012, 10:24:13 AM9/19/12
to Agusti...@ictja.csic.es, ggp...@googlegroups.com
Have you tried just converting "temperature" into a factor using either
"?as.factor" or "?factor"

David J.

Agustin Lobo

unread,
Sep 19, 2012, 12:57:12 PM9/19/12
to David Johnston, ggp...@googlegroups.com
Thanks for your answer.
I had tried with as. character(temperature), I should have mentioned
it, which yields a similar result.
The problem is that what I would like is keeping the continuous color
scheme, having a color bar in which
the ticks and labels are set in accordance to the values of the
glasses. That is, the ticks and labels of the legend
would not be regularly distributed (as by default), but in the places
that correspond to the glasses. This would be best for
a continuous variable (temperature).
But factor(temperature) is a good second option.

Agus
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
Reply all
Reply to author
Forward
0 new messages