I am struggling here to figure out the default linetypes used in ggplot2. I have a dataframe as follows:
test <- structure(list(time = c(151.04167175293, 151.125015258789, 151.20832824707,
151.29167175293, 151.375030517578, 151.45832824707, 151.54167175293,
151.625015258789, 151.70832824707, 151.79167175293, 151.875030517578,
151.95832824707, 151.08332824707, 151.166687011719, 151.250030517578,
151.333343505859, 151.41667175293, 151.5, 151.58332824707, 151.666687011719,
151.750030517578, 151.833343505859, 151.91667175293, 151.04167175293,
151.125015258789, 151.20832824707, 151.29167175293, 151.375030517578,
151.45832824707, 151.54167175293, 151.625015258789, 151.70832824707,
151.79167175293, 151.875030517578, 151.95832824707, 151.08332824707,
151.166687011719, 151.250030517578, 151.333343505859, 151.41667175293,
151.5, 151.58332824707, 151.666687011719, 151.750030517578, 151.833343505859,
151.91667175293, 151.04167175293, 151.125015258789, 151.20832824707,
151.29167175293, 151.375030517578, 151.45832824707, 151.54167175293,
151.625015258789, 151.70832824707, 151.79167175293, 151.875030517578,
151.95832824707, 151.08332824707, 151.166687011719, 151.250030517578,
151.333343505859, 151.41667175293, 151.5, 151.58332824707, 151.666687011719,
151.750030517578, 151.833343505859, 151.91667175293, 151.04167175293,
151.125015258789, 151.20832824707, 151.29167175293, 151.375030517578,
151.45832824707, 151.54167175293, 151.625015258789, 151.70832824707,
151.79167175293, 151.875030517578, 151.95832824707, 151.08332824707,
151.166687011719, 151.250030517578, 151.333343505859, 151.41667175293,
151.5, 151.58332824707, 151.666687011719, 151.750030517578, 151.833343505859,
151.91667175293), value = c(0, 0, 5.61033323376278e-29, 1.54657131948427e-17,
9.66035151178657e-12, 5.10066877623672e-09, 5.13016118475207e-08,
5.63439357392781e-08, 2.30620536001425e-08, 9.08235708863003e-09,
8.37633162831253e-09, 1.55146210545354e-07, 0, 0, 2.25358956126054e-21,
2.08607626615495e-13, 1.98955163455139e-09, 9.66092130738616e-08,
1.91719223607834e-07, 1.09957049687637e-07, 3.104455004177e-08,
1.31108741641128e-08, 6.10190298289126e-08, 0, 0, 0, 0, 3.2789574202628e-30,
6.73093043024932e-24, 7.93898871359986e-21, 1.51219769988266e-19,
3.67432930162413e-19, 7.19692007469365e-19, 3.20756611951269e-18,
4.69377782154479e-17, 0, 0, 0, 5.28026380068047e-35, 6.81666051928849e-28,
2.74272295486945e-23, 3.82383180911782e-21, 1.74006456826736e-20,
4.48768165153377e-20, 1.60533888309098e-19, 1.53676095741939e-18,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 8.71725244784488e-30, 1.04201812373392e-23,
2.36111112593732e-21, 5.04498618818828e-20, 1.39487078953905e-19,
9.53610723085965e-19, 2.04732743716978e-17, 2.28480170675856e-15,
0, 0, 0, 1.1415638533226e-32, 3.46081290989027e-27, 5.11190859597535e-23,
2.60199456175554e-21, 8.88056339654886e-21, 2.0802860544737e-20,
3.12119181655233e-19, 3.69406751642014e-17), id = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("a",
"b", "c", "d", "e", "f"), class = c("ordered", "factor")), dis = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("50",
"100", "250", "50(nothing)"), class = c("ordered", "factor"))), .Names = c("time",
"value", "id", "dis"), row.names = c("1", "3", "5", "7", "9",
"11", "13", "15", "17", "19", "21", "23", "722", "724", "726",
"728", "730", "732", "734", "736", "738", "740", "742", "4321",
"4323", "4325", "4327", "4329", "4331", "4333", "4335", "4337",
"4339", "4341", "4343", "5042", "5044", "5046", "5048", "5050",
"5052", "5054", "5056", "5058", "5060", "5062", "8641", "8643",
"8645", "8647", "8649", "8651", "8653", "8655", "8657", "8659",
"8661", "8663", "9362", "9364", "9366", "9368", "9370", "9372",
"9374", "9376", "9378", "9380", "9382", "12", "32", "52", "72",
"92", "112", "132", "152", "172", "192", "212", "232", "7221",
"7241", "7261", "7281", "7301", "7321", "7341", "7361", "7381",
"7401", "7421"), class = "data.frame")
Now, I plot the above dataframe as follows:
library(ggplot2)
ggplot(test)+
geom_line(aes(time,value,linetype=dis))+
facet_wrap(~id,ncol=2)+theme_bw()+
ylab("concentration ")+coord_cartesian(xlim=c(151,181),ylim=c(-0.15,0.75))+ labs(linetype="")+
theme(panel.margin = unit(1, "lines"))+ xlab("")+
scale_x_continuous(limits=c(151,181),breaks=seq(151,181,5))+
scale_y_continuous(limits=c(-0.15,1.75),breaks=seq(-0.15,1.75,0.15))+
theme(legend.position="top",legend.key =element_blank())
The output is as follows:
What I am trying to know is by default what linetypes are used ? Because when I try to use scale_linetype_manual("", values=c(1,2,3,4))
then it doesn't produce the same linetypes
as above.
The figure obtained by specifying linetype above is
Would someone clarify this issue ? Is it possible to achieve the same effect by specifying the linetype ? The reason I am trying to do this is before I had use default and now I need to change one linetype.
I tried with several linetypes
but cannot figure out what linetypes
are used when we don't manually specify linetype. Thanks
I don't have data for dis = "100" and "250" over here but should be able to have the same linetype.
EDIT
The link to full dataset is as follows: https://dl.dropboxusercontent.com/u/9267938/dputtest.rda
Here is one way to figure out the default
linetypes
, in which order they are used byggplot
, and their names.Apparently, there are 13 default linetypes in
ggplot
. If you look at data in the plot object, you find the corresponding 'names' of the differentlinetype
s.See
?aes_linetype_size_shape
for how to interpret the 'numerical names' and howlinetype
can be specified using "either an integer, a name, or with a string of an even number (up to eight) of characters". A similar description can also be found in?par
:lty
and "Line Type Specification"); "The five standard dash-dot line types (lty = 2:6
) correspond toc("44", "13", "1343", "73", "2262")
.As explained in this answer, to get
scale_linetype_manual(...)
to do what you want, you have to setvalues=...
to a named vector, as follows:Compare this to the result when you set
lt
as follows:Have a look at this overview, you can see which numbers correspond with which linetypes. So if you want to manually assign the default values you would probably have to use:
scale_linetype_manual(values=c(1,3,2,5))