[R] FW: dotplot

Duncan Mackay dulcalma at bigpond.com
Sat Feb 27 06:23:37 CET 2016

Forgot to send to list

-----Original Message-----
From: Duncan Mackay [mailto:dulcalma at bigpond.com] 
Sent: Sunday, 17 May 2015 10:49
To: R
Subject: RE: [R] dotplot

if this is using lattice panel.dotplot gives the clues
The vertical lines are inserted by panel abline.

You can make your own panel.dotplot function by removing panel.abline which
uses col.line for the vertical line colour
A quick fix is by making col.line = "transparent". If you want to add lines
this may cause trouble for you

dotplot(val ~ lot, tmp,
        col.line = "transparent",
        ylab = "values", xlab="lot", scales=list(rot=30), aspect=1,
        pch=tmp$sybm, col=tmp$color)



Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au

-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Daniel
Sent: Sunday, 17 May 2015 06:45
To: r-help at r-project.org
Subject: Re: [R] dotplot

On 5/16/2015 1:19 PM, Daniel Nordlund wrote:
> On 5/16/2015 12:32 PM, li li wrote:
>> Hi all,
>>    I wrote the following code and have two questions:
>>    (1) As you can see, I would like different colors for different
>> types. It does not come out that way in the graph from this code.
>> Anyone know how to fix this?
>>     (2) How do I made the lots number on x axis eligible to read?
>>     (3) How do I remove the verticle line in the graph.
>>      Thanks for your help.
>>        Hanna
>> lot <- as.character(c("D1300000" ,"D1300005" ,"D1300010", "D1300015",
>> "D1300020",
>>           "D1300025" ,"D1300030" ,"D1300035", "D1300040",  "D1300045",
>>           "D1300000" ,"D1300005" ,"D1300010", "D1300015",  "D1300020",
>>           "D1300025" ,"D1300030" ,"D1300035", "D1300040",  "D1300045",
>>           "D1300000" ,"D1300005" ,"D1300010", "D1300015",  "D1300020",
>>           "D1300025" ,"D1300030" ,"D1300035", "D1300040",  "D1300045"))
>> val <- rnorm(30)
>> type <- rep(1:3,each=10)
>> tmp <- as.data.frame(cbind(val, type, lot))
>> tmp$sybm <- rep(c(1, 12, 16), each=10)
>> tmp$color <- rep(c("blue", "red", "green"), each=10)
>> tmp$val <- as.numeric(tmp$val)
>> dotplot(val ~ lot, tmp,
>>          ylab = "values", xlab="lot", aspect=1,
>>          pch=tmp$sybm, color=tmp$color)
> Li Li,
> 1. if the dotplot function you are referring to is from the lattice
> package, then the correct name for the "color" parameter is col.  You
> could just use col=type to get different colors but you won't have
> control over the colors chosen.  I created a vector, color, specifying
> the colors and the order they will be applied.
> 2.  the scales parameter is what you are looking for.  The parameter is
> looking for a list which consists of name=value pairs. You can rotate
> the labels by a specified number of degrees.  In my example, I chose 30
> degrees, rot=30.
> 3. I don't know how to eliminate the vertical lines, but if you read the
> lattice documentation, you will find it (if it is possible).
> color=c("blue", "red", "green")
> dotplot(val ~ lot, tmp,
>          ylab = "values", xlab="lot", scales=list(rot=30), aspect=1,
>          pch=tmp$sybm, col=color)
> Hope this is helpful,
> Dan

I apologize; my use of the color vector was incorrect.  You could just 
use the tmp$color values with the correct color parameter name.  Like

dotplot(val ~ lot, tmp,
         ylab = "values", xlab="lot", scales=list(rot=30), aspect=1,
         pch=tmp$sybm, col=tmp$color)


Daniel Nordlund
Bothell, WA USA

R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
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