[R] Adding a second Y axis on a dotplot

Jim Lemon drjimlemon at gmail.com
Sat Sep 12 03:27:06 CEST 2015


Hi Hanna,
Not within lattice, but you could try this:

plot(as.numeric(tmp1$lot[tmp1$trt=="trt1"]),
 tmp1$result[tmp1$trt=="trt1"],xlab="lot",
 ylab="Values",type="p",axes=FALSE,
 col="red",pch=1,ylim=c(68,120))
abline(v=1:9,col="lightgray",lty=2)
box()
library(plotrix)
axis(1,at=1:9,labels=as.character(tmp1$lot[tmp1$trt=="trt1"]))
points(as.numeric(tmp1$lot[tmp1$trt=="trt2"]),
 tmp1$result[tmp1$trt=="trt2"],col="blue",pch=2)
fullaxis(2,at=seq(70,120,by=10),col="red")
fullaxis(4,at=seq(70,120,by=10),labels=7:12,col="blue")
axis.break(2,breakpos=68.5)
axis.break(4,breakpos=68.5)

Jim


On Sat, Sep 12, 2015 at 3:30 AM, li li <hannah.hlx at gmail.com> wrote:

> Hi all,
>   I plotted a dotplot based on the data below and code below. I would
> like to add another yaxis on the right with a different col, different
> tickmarks and a different label. Can anyone give some help?Thanks very
> much!!
>      Hanna
>
>
> > tmp1
>    result  lot  trt trtsymb trtcol
> 1      98 lot1 trt1       1   blue
> 2      99 lot2 trt1       1   blue
> 3      98 lot3 trt1       1   blue
> 4     100 lot4 trt1       1   blue
> 5     100 lot5 trt1       1   blue
> 6     101 lot6 trt1       1   blue
> 7     101 lot7 trt1       1   blue
> 8      99 lot8 trt1       1   blue
> 9     100 lot9 trt1       1   blue
> 10     94 lot1 trt2      16    red
> 11    105 lot2 trt2      16    red
> 12     87 lot3 trt2      16    red
> 13    119 lot4 trt2      16    red
> 14     96 lot5 trt2      16    red
> 15    113 lot6 trt2      16    red
> 16    106 lot7 trt2      16    red
> 17     71 lot8 trt2      16    red
> 18     95 lot9 trt2      16    red
>
>
> library(lattice)
> dotplot(result ~ lot, tmp1, cex=1.1,  ylab = "values", xlab="lot",
> jitter.y = F, aspect=1.0,
>         pch=tmp1$trtsymb, col=tmp1$trtcol, scales=list(rot=30),
> main="", key = list(text = list(labels = c("trt1", "trt2"),cex=c(0.9,0.9)),
> points = list(pch =c(1,12), col =c("blue", "red")),
> space = "right"))
>
> ______________________________________________
> 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list