[R] How to convert line plot to lattice xtplot?
Luigi Marongiu
m@rong|u@|u|g| @end|ng |rom gm@||@com
Tue Oct 12 19:09:05 CEST 2021
Awesome, thanks!
On Tue, Oct 12, 2021 at 4:20 PM Bert Gunter <bgunter.4567 using gmail.com> wrote:
>
> You have misspecified the grouping.
>
> df$subs <- rep(1:4, e=4)
>
> xyplot(Value ~ Concentration,
> groups = subs, data = df, ##... etc.
>
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Tue, Oct 12, 2021 at 6:49 AM Luigi Marongiu <marongiu.luigi using gmail.com> wrote:
>>
>> Hello,
>> I have drawn data from a dataframe as follows:
>> ```
>> Substance = rep(c("A", "B", "C", "D"),4)
>> Concentration = rep(1:4,4)
>> Value = c(62.80666667, 116.26333333, 92.26000000, 9.87333333, 14.82333333,
>> 92.37333333, 98.95666667, 1.48333333, 0.64666667, 50.66000000,
>> 25.75333333, 0.69000000, 0.21666667, 7.40666667, 6.92000000,
>> 0.06333333)
>> df = data.frame(Substance, Concentration, Value, stringsAsFactors = FALSE)
>> Value = c(15.2974126, 16.3196089, 57.4294280, 9.1943370, 20.5567321,
>> 14.0874424,
>> 38.3626672, 0.3780653, 0.4738495, 37.9124874, 16.2473916, 0.7218726,
>> 0.2498666, 8.4537585, 10.8058456, 0.1096966)
>> dfsd = data.frame(Substance, Concentration, Value, stringsAsFactors = FALSE)
>> COLS = c("gold", "green", "purple", "blue")
>>
>> plot(df$Value[df$Substance == "A"] ~ unique(df$Concentration),
>> xlab=expression(bold(paste("Concentration (", mu, "M)"))),
>> ylab=expression(bold("Value")),
>> type = "o", col = "gold", pch = 16,
>> xaxt="n", las=3, log = "x",
>> ylim = c(0, max(df$Value+dfsd$Value))
>> )
>> points(df$Value[df$Substance == "B"] ~ unique(df$Concentration),
>> type = "o", col = "green", pch = 16)
>> points(df$Value[df$Substance == "C"] ~ unique(df$Concentration),
>> type = "o", col = "purple", pch = 16)
>> points(df$Value[df$Substance == "D"] ~ unique(df$Concentration),
>> type = "o", col = "blue", pch = 16)
>> legend("topright", legend = LETTERS[1:4],
>> lty = 1, pch = 16,
>> col = COLS)
>> ```
>> I then tried to use lattice but I got a stripplot instead. At each x
>> (1:4) only one group (A:D) is drawn. What am I missing?
>> ```
>> library(lattice)
>> xyplot(Value ~ Concentration,
>> group = Substance, data = df,
>> pch = 16, cex = 1.2, type = "b",
>> xlab=expression(bold(paste("Concentration (", mu, "M)"))),
>> ylab=expression(bold("Infection rate")),
>> col=COLS,
>> scales = list(x = list(log = 10, at=c(unique(df$Concentration))
>> )
>> ),
>> key = list(space="top", columns=4, col = "black",
>> points=list(pch=c(16, 16, 16, 16),
>> col=COLS
>> ),
>> text=list(c("A", "B", "C", "D")
>> )
>> )
>> )
>> ```
>>
>> Thank you
>>
>> --
>> Best regards,
>> Luigi
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
--
Best regards,
Luigi
More information about the R-help
mailing list