jhpantel · GitHub

Can I get more clarification on how to draw separate elements using the facet argument? I share this in case it helps work with implementing additional facet elements:

# generate data
lambda1 <- 1.8
lambda2 <- 0.7
x <- 0:10
p1 <- dpois(x,lambda1)
p2 <- dpois(x,lambda2)
dp <- data.frame(x=c(x,x),p=c(p1,p2),lambda=rep(c(lambda1,lambda2),each=length(x)))
dp$lambda <- as.factor(dp$lambda)
# plot
plt(p ~ x,
    facet = ~lambda,
    data=dp,
    type="h",
    lwd=2,
    col="skyblue",
    draw=c(axis(1,at=x,labels=x),
           points(p~x,data=dp,col="black")))

As we can see, it draws both sets of points (not divided by facet). I can't add facet to the points command in the draw argument (of course, as its a base R command).

I could only get this to work by using plt_add(), but here I cannot manage shared y-axis limits (if I remove the free=TRUE argument, the points are drawn offset from where they should be).

plt(p ~ x,
    facet=~lambda,
    data=dp,
    type="h",
    lwd=2,
    col="skyblue",
    facet.args=list(free=TRUE),
    ylim=c(0.,0.5)
)
plt_add(type="p")

Thank you very much!

Read the original on github.com ↗