[R] ggplot2: mixing colour and linetype in geom_line
Benoit Boulinguiez
benoit.boulinguiez at ensc-rennes.fr
Thu Sep 10 08:59:40 CEST 2009
many thanks Felipe
I didn't know the melt function.
I'll have a close look at it.
Regards/Cordialement
Benoit Boulinguiez
-----Message d'origine-----
De : Felipe Carrillo [mailto:mazatlanmexico at yahoo.com]
Envoyé : mercredi 9 septembre 2009 20:40
À : r-help at r-project.org; Benoit Boulinguiez
Objet : Re: [R] ggplot2: mixing colour and linetype in geom_line
Is this what you want?
x <- structure(list(Temp = c(25.9765, 26.57025, 27.164, 27.7565, 28.34892,
28.94142, 29.53125, 30.12233, 30.71483, 31.30983, 31.90233, 32.49475,
33.08458, 33.67575, 34.26558, 34.85933, 35.45183, 36.04683, 36.63933,
37.23042, 37.82417, 38.414), X22 = c(4.62e-12, 4.73e-12, 4.62e-12, 4.57e-12,
4.64e-12, 4.71e-12, 4.7e-12, 4.64e-12, 4.71e-12, 4.51e-12, 4.52e-12,
4.47e-12, 4.58e-12, 4.56e-12, 4.53e-12, 4.54e-12, 4.55e-12, 4.54e-12,
4.53e-12, 4.5e-12, 4.55e-12, 4.57e-12), X43 = c(6.14e-11, 6.11e-11,
6.04e-11, 6.06e-11, 6.01e-11, 6.01e-11, 5.93e-11, 5.91e-11, 5.91e-11,
5.88e-11, 5.8e-11, 5.8e-11, 5.79e-11, 5.75e-11, 5.74e-11, 5.7e-11, 5.67e-11,
5.66e-11, 5.61e-11, 5.57e-11, 5.58e-11, 5.57e-11 ), X44 = c(3.93e-10,
3.91e-10, 3.91e-10, 3.9e-10, 3.89e-10, 3.88e-10, 3.87e-10, 3.86e-10,
3.85e-10, 3.85e-10, 3.85e-10, 3.83e-10, 3.83e-10, 3.82e-10, 3.8e-10,
3.8e-10, 3.79e-10, 3.78e-10, 3.77e-10, 3.77e-10, 3.76e-10, 3.75e-10), X45 =
c(1.29e-11, 1.28e-11, 1.27e-11, 1.27e-11, 1.28e-11, 1.27e-11, 1.27e-11,
1.26e-11, 1.25e-11, 1.23e-11, 1.23e-11, 1.24e-11, 1.23e-11, 1.22e-11,
1.23e-11, 1.22e-11, 1.21e-11, 1.2e-11, 1.19e-11, 1.21e-11, 1.19e-11,
1.2e-11), X48 = c(2.05e-10, 2.05e-10, 2.05e-10, 2.03e-10, 2.03e-10,
2.02e-10, 2.02e-10, 2.01e-10, 2.01e-10, 2e-10, 1.99e-10, 1.99e-10, 1.98e-10,
1.97e-10, 1.97e-10, 1.96e-10, 1.96e-10, 1.95e-10, 1.94e-10, 1.94e-10,
1.94e-10, 1.92e-10),
X58 = c(6.78e-12, 6.8e-12, 6.87e-12, 6.79e-12, 6.75e-12,
6.67e-12, 6.65e-12, 6.63e-12, 6.59e-12, 6.54e-12, 6.6e-12,
6.57e-12, 6.57e-12, 6.43e-12, 6.42e-12, 6.48e-12, 6.38e-12,
6.37e-12, 6.45e-12, 6.35e-12, 6.29e-12, 6.3e-12), X60 = c(9.31e-12,
9.43e-12, 9.28e-12, 9.26e-12, 9.18e-12, 9.24e-12, 9.2e-12,
9.11e-12, 9.17e-12, 9e-12, 9.09e-12, 8.95e-12, 9.02e-12,
8.89e-12, 8.97e-12, 8.93e-12, 8.86e-12, 8.9e-12, 8.85e-12,
8.82e-12, 8.86e-12, 8.8e-12)), .Names = c("Temp", "X22", "X43", "X44",
"X45", "X48", "X58", "X60"), class = "data.frame", row.names = c("1", "2",
"3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16",
"17", "18", "19", "20", "21", "22"))
attach(x)
xmelt <- melt(x,id.vars="Temp");head(xmelt)
qplot(Temp,value,colour=variable,linetype=variable,data=xmelt,geom="line")
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
--- On Wed, 9/9/09, Benoit Boulinguiez <benoit.boulinguiez at ensc-rennes.fr>
wrote:
> From: Benoit Boulinguiez <benoit.boulinguiez at ensc-rennes.fr>
> Subject: [R] ggplot2: mixing colour and linetype in geom_line
> To: r-help at r-project.org
> Date: Wednesday, September 9, 2009, 8:24 AM Hi all,
>
> I try to represent a multiple curve graphic where the x-axis is the
> temperature and the different y-axes are the different X
> (X22,X43,X44...)
> some X corresponds to the same molecule (22 and 44 are for
> CO2 for instance)
> so I use the same colour for them.
>
> I wanna mix the linetype with the colour to be able to visually see
> the difference between X43 and X45 The best I have done up to now is
> this code but it crashes with :"Error in col2rgb(colour, TRUE) :
> invalid color name 'AA'"
>
> if I skip the linetype in geom it works perfectly of course
>
>
> THT_N2_ATGMS_plot<-ggplot(THT_N2_ATGMS,aes(x=Temp)) +
>
> # geom_line(aes(y=X22,colour="CO2")) + #
> geom_line(aes(y=X44,colour="CO2")) +
>
> geom_line(aes(y=X43,colour="AA",linetype="43")) +
> geom_line(aes(y=X45,colour="AA",linetype="45"))
>
>
>
> data set looks like:
> Temp
> X22 X43
> X44 X45 X48
> X58 X60
> 1 25.97650 4.62e-12 6.14e-11 3.93e-10 1.29e-11 2.05e-10 6.78e-12
> 9.31e-12
> 2 26.57025 4.73e-12 6.11e-11 3.91e-10 1.28e-11 2.05e-10 6.80e-12
> 9.43e-12
> 3 27.16400 4.62e-12 6.04e-11 3.91e-10 1.27e-11 2.05e-10 6.87e-12
> 9.28e-12
> 4 27.75650 4.57e-12 6.06e-11 3.90e-10 1.27e-11 2.03e-10 6.79e-12
> 9.26e-12
> 5 28.34892 4.64e-12 6.01e-11 3.89e-10 1.28e-11 2.03e-10 6.75e-12
> 9.18e-12
> 6 28.94142 4.71e-12 6.01e-11 3.88e-10 1.27e-11 2.02e-10 6.67e-12
> 9.24e-12
> 7 29.53125 4.70e-12 5.93e-11 3.87e-10 1.27e-11 2.02e-10 6.65e-12
> 9.20e-12
> 8 30.12233 4.64e-12 5.91e-11 3.86e-10 1.26e-11 2.01e-10 6.63e-12
> 9.11e-12
> 9 30.71483 4.71e-12 5.91e-11 3.85e-10 1.25e-11 2.01e-10 6.59e-12
> 9.17e-12 10 31.30983 4.51e-12 5.88e-11 3.85e-10
> 1.23e-11 2.00e-10 6.54e-12 9.00e-12
> 11 31.90233 4.52e-12 5.80e-11 3.85e-10
> 1.23e-11 1.99e-10 6.60e-12 9.09e-12
> 12 32.49475 4.47e-12 5.80e-11 3.83e-10
> 1.24e-11 1.99e-10 6.57e-12 8.95e-12
> 13 33.08458 4.58e-12 5.79e-11 3.83e-10
> 1.23e-11 1.98e-10 6.57e-12 9.02e-12
> 14 33.67575 4.56e-12 5.75e-11 3.82e-10
> 1.22e-11 1.97e-10 6.43e-12 8.89e-12
> 15 34.26558 4.53e-12 5.74e-11 3.80e-10
> 1.23e-11 1.97e-10 6.42e-12 8.97e-12
> 16 34.85933 4.54e-12 5.70e-11 3.80e-10
> 1.22e-11 1.96e-10 6.48e-12 8.93e-12
> 17 35.45183 4.55e-12 5.67e-11 3.79e-10
> 1.21e-11 1.96e-10 6.38e-12 8.86e-12
> 18 36.04683 4.54e-12 5.66e-11 3.78e-10
> 1.20e-11 1.95e-10 6.37e-12 8.90e-12
> 19 36.63933 4.53e-12 5.61e-11 3.77e-10
> 1.19e-11 1.94e-10 6.45e-12 8.85e-12
> 20 37.23042 4.50e-12 5.57e-11 3.77e-10
> 1.21e-11 1.94e-10 6.35e-12 8.82e-12
> 21 37.82417 4.55e-12 5.58e-11 3.76e-10
> 1.19e-11 1.94e-10 6.29e-12 8.86e-12
> 22 38.41400 4.57e-12 5.57e-11 3.75e-10
> 1.20e-11 1.92e-10 6.30e-12 8.80e-12
>
>
>
> Regards/Cordialement
>
> -------------
> Benoit Boulinguiez
> Ph.D student
> Ecole de Chimie de Rennes (ENSCR) Bureau 1.20 Equipe CIP UMR CNRS 6226
> "Sciences Chimiques de Rennes"
> Avenue du Général Leclerc
> CS 50837
> 35708 Rennes CEDEX 7
> Tel 33 (0)2 23 23 80 83
> Fax 33 (0)2 23 23 81 20
> <http://www.ensc-rennes.fr/> http://www.ensc-rennes.fr/
>
>
>
> [[alternative HTML version deleted]]
>
>
> -----Inline Attachment Follows-----
>
> ______________________________________________
> R-help at r-project.org
> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>
More information about the R-help
mailing list