0

i'm using the package 'latticeExtra' to plot with double Y axis as i show in my code:

library(latticeExtra)


MS <- xyplot(Tabla.Rosetta.dt[,14] ~ Tabla.Rosetta.dt[,1], Tabla.Rosetta.dt, type='l', col="#9933CC", ylab = 'Meteoscore', 
key=list(space="topright",
         lines=list(col=c("#9933CC","#FF9933"), lty=c(1,1), lwd=6),
         text=list(c("Meteoscore"," RSP"))
))
RSP <- xyplot(Tabla.Rosetta.dt[,2] ~ Tabla.Rosetta.dt[,1], Tabla.Rosetta.dt, type='l', col="#FF9933", ylab = 'RSP frequency', xlab = 'Dates')

doubleYScale(MS, RSP, add.ylab2 = TRUE, use.style=FALSE)

but the input 'key' doesn't work. I would like add legend in topright but i don't know how do ir. ideas? Thanks for your time

Phil
  • 7,287
  • 3
  • 36
  • 66
Bufal
  • 11
  • 2
  • 1
    Please share some reproducible data using `dput`? – Quinten Jun 03 '22 at 17:04
  • 1
    It's easier to help you if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jun 03 '22 at 17:26
  • Okay, sorry guys it was my first post, i think i'm gonna delete and create a new one – Bufal Jun 04 '22 at 16:09

1 Answers1

0

Please read the info at the top of the tag and note that all questions should be reproducible. Tabla.Rosetta.dt is missing so in the absence of that we will use the SeatacWeather data frame from latticeExtra and adjust the example to that adding panel.key in a new layer specifying packets=3 to the layer.

library(latticeExtra)

data(SeatacWeather)
temp <- xyplot(max.temp + min.temp ~ day | month,
                data = SeatacWeather, type = "l", layout = c(3, 1))
rain <- xyplot(precip ~ day | month, data = SeatacWeather, type = "h")

doubleYScale(temp, rain, style1 = 0, style2 = 3, add.ylab2 = TRUE) +
  layer(panel.key(text = c("max temp", "min temp", "rain"), 
    lines = TRUE, points = FALSE), 
    packets = 3)

screenshot

G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341