Hello, I am drawing some data with lattice using: ``` library(lattice) COLS = c("gold", "forestgreen", "darkslategray3", "purple") xyplot(Value ~ Concentration, group = Substance, data = inf_avg, 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(inf_avg$Concentration)) ) ), key = list(space="top", columns=4, col = "black", points=list(pch=c(16, 16, 16, 16), col=COLS, text=list(c("6-PN", "8-PN", "IX", "XN") ) ) ), panel = function(x,y) { panel.xyplot(x,y) errbar() } ) ``` It all works but the legend only shows the colored dots, there is no text. Is it something missing from the syntax? Thanks -- Best regards, Luigi
On Mon, Oct 11, 2021 at 5:17 PM Luigi Marongiu <marongiu.luigi at gmail.com> wrote:> > Hello, > I am drawing some data with lattice using: > ``` > library(lattice) > COLS = c("gold", "forestgreen", "darkslategray3", "purple") > xyplot(Value ~ Concentration, > group = Substance, data = inf_avg, > 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(inf_avg$Concentration)) > ) > ), > key = list(space="top", columns=4, col = "black", > points=list(pch=c(16, 16, 16, 16), > col=COLS, > text=list(c("6-PN", "8-PN", "IX", "XN") > ) > ) > ), > panel = function(x,y) { > panel.xyplot(x,y) > errbar() > } > ) > ``` > It all works but the legend only shows the colored dots, there is no > text. Is it something missing from the syntax?Your text component is nested inside the points component. I think you want it outside, e.g., xyplot(1 ~ 1, key = list(space="top", columns=4, col = "black", points=list(pch=c(16, 16, 16, 16), col=COLS), text=list(c("6-PN", "8-PN", "IX", "XN")) )) Best, -Deepayan> Thanks > > -- > Best regards, > Luigi > > ______________________________________________ > R-help at 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.
Richard M. Heiberger
2021-Oct-11 14:22 UTC
[R] [External] Missing text in lattice key legend
looks like a paren outof place. the text is inside the points. it should be parallel to the points in the calling sequence. Get Outlook for iOS<https://aka.ms/o0ukef> ________________________________ From: R-help <r-help-bounces at r-project.org> on behalf of Luigi Marongiu <marongiu.luigi at gmail.com> Sent: Monday, October 11, 2021 7:46:36 AM To: r-help <r-help at r-project.org> Subject: [External] [R] Missing text in lattice key legend Hello, I am drawing some data with lattice using: ``` library(lattice) COLS = c("gold", "forestgreen", "darkslategray3", "purple") xyplot(Value ~ Concentration, group = Substance, data = inf_avg, 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(inf_avg$Concentration)) ) ), key = list(space="top", columns=4, col = "black", points=list(pch=c(16, 16, 16, 16), col=COLS, text=list(c("6-PN", "8-PN", "IX", "XN") ) ) ), panel = function(x,y) { panel.xyplot(x,y) errbar() } ) ``` It all works but the legend only shows the colored dots, there is no text. Is it something missing from the syntax? Thanks -- Best regards, Luigi ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=04%7C01%7Crmh%40temple.edu%7C3f303633d643499924e208d98cacdaef%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637695496888670932%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=98vQNMB7OcS%2B2R73ZMngEeg%2BP6PeP3oCAOUDHxs9SU8%3D&reserved=0 PLEASE do read the posting guide https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=04%7C01%7Crmh%40temple.edu%7C3f303633d643499924e208d98cacdaef%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637695496888670932%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=1yzXmD57qql7UXEKNqdK8Iq1vhfkUYf%2BpX8gvfvD3p0%3D&reserved=0 and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]]