[R] Dot plot with two grouping variables concurrently

Weidong Gu anopheles123 at gmail.com
Sun Aug 21 16:33:13 CEST 2011


> Q1.
>
> Right now I like to know how to get the dual coding working on the points on
> a dotplot and also annotate these in a key.  Specifically I'm attempting to
> code the fill of the points by a variable called 'Commodity' but would like
> have different symbols to refelect a second variable called 'Year' (say
> square, triangle and circle for different years).

You can custumize pch as to reflect the levels of "Year" in both your
dotplot and key

my.pch<- 1:length(levels(Cal_dat$Year)) ### for example

Then, use my.pch in the places of  pch in your codes of dotplot and key

HTH

Weidong Gu

> My code so far is as follows:
>
> ## initalise
> library("lattice")
>
> ##read the data to a variable
> Cal_dat <- read.table("Calibration2.dat",header = TRUE,sep = "\t",)
>
> ## set up plotting colours for the fills
> col.pat<-c("violet","cyan","green","red","blue","black","yellow")
>
> ##set up the plot key to be inside the plot
> plot.key<-list(
>        corner=c(1,0),
>        text=list(levels(Cal_dat$Commodity)),
>        title="Ore type",
>        points=list(pch=21,cex=1.3,fill=col.pat,col="black")
> )
>
> ##set some parameters for the dotplot
> trellis.par.set(
>        dot.line=list(col = "transparent"),
>        axis.line=list(col = "grey90"),
>        axis.text=list(col ="grey50", cex=0.8),
>        panel.background=list(col="grey98"),
>        par.xlab.text= list(col="grey50")
> )
>
> ## Create the dot plot
> dotplot(reorder(Mine, Resc_Gt)~ Resc_Gt,groups=Commodity,
>      data=Cal_dat,
>        cex=1.2,
>        pch=21,
>        aspect=2.0,
>        key=plot.key,
>        col="black",
>        fill=col.pat,
>        origin=0,
>        type = c("p", "h"),
>        main = "Resource Tonnage",
>        xlab= "tonnes (billions)"
> )
>
> The dot plot so far is attached as well as the input data.
>
> Q2
>
> I'm puzzled by the waring message (below) I get when runnin the current code
> as follows (What does this mean and why does it occur).
>
> "Warning message:
> In trellis.par.set(dot.line = list(col = "transparent"), axis.line =
> list(col = "grey90"),  :
>  Note: The default device has been opened to honour attempt to modify
> trellis settings"
>
> Q3
>
> Can anybody recommend a good 'starters' book for learning plotting in R that
> is reasonably clear on the basics.  My primary interest is the graphing
> tools that are in lattice (hence trying the Deepayan Sarkar book), but I'm
> finding this guide rather tough going.
>
> Thanks in advance - MarkM
>
> http://r.789695.n4.nabble.com/file/n3758248/Calibration2.dat
> Calibration2.dat
> http://r.789695.n4.nabble.com/file/n3758248/Ranked_boxplot_by_commodity.png
> Ranked_boxplot_by_commodity.png
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Dot-plot-with-two-grouping-variables-concurrently-tp3758248p3758248.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>



More information about the R-help mailing list