An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110817/2aedd6ec/attachment.pl>
dotchart vs. dotplot ... groups
3 messages · mkzodet at comcast.net, Brian Diggs, Deepayan Sarkar
1 day later
On 8/17/2011 11:29 AM, mkzodet at comcast.net wrote:
I'm trying to create a dotplot with some grouping.
I've been able to create what I want using dotchart (basic
graphics), but can't quite get it using dotplot (lattice). I prefer
to use lattice (or ggplot2) because I think it's a bit easier to
control some other aspects of the plot appearance.
Basically, w/ lattice I've not been able to get the y-axis label to
include the group variable.
I'd like...
A
1
2
B
1
2
3
4
C
1
2
3
I'm getting...
1
2
1
2
3
4
1
2
3
The following example code illustrates....
set.seed(18)
dta<- data.frame(var1=factor(c("A", "A", "B", "B", "B", "B", "C", "C", "C")),
var2=c(1,2,1,2,3,4,1,2,3),
var3=round(runif(9,1,10),1),
plotorder=9:1)
dta
windows(3,3)
dotchart(dta$var3[order(dta$var1, -dta$var2)], groups=dta$var1,
labels=dta$var2[order(dta$var1, -dta$var2)], cex=.75,
gcolor=c("blue", "red", "dark green"),
col=c(rep("blue",2), rep("red",4), rep("dark green",3)),
axes=NULL)
windows(3,3)
dotplot(data=dta, plotorder~var3, groups=var1, col=c("blue", "red", "dark green"),
scales=list(y=list(labels=dta$var2[order(dta$plotorder)])))
Something similar (though still not what you wanted) using ggplot would be: dev.new(width=3,height=3) ggplot(dta, aes(x=var3, y=var2)) + geom_point() + scale_y_reverse(breaks=1:4, expand=c(0,0.5)) + facet_grid(var1~., scales="free", space="free") + theme_bw()
Thanks. Marc R 2.13.0 (2011-04-13) Windows XP [[alternative HTML version deleted]]
Brian S. Diggs, PhD Senior Research Associate, Department of Surgery Oregon Health & Science University
On Wed, Aug 17, 2011 at 11:59 PM, <mkzodet at comcast.net> wrote:
I'm trying to create a dotplot with some grouping.
I've been able to create what I want using dotchart (basic graphics), but can't quite get it using dotplot (lattice). I prefer to use lattice (or ggplot2) because I think it's a bit easier to control some other aspects of the plot appearance.
Basically, w/ lattice I've not been able to get the y-axis label to include the group variable.
I'd like...
A
1
2
B
1
2
3
4
C
1
2
3
I'm getting...
1
2
1
2
3
4
1
2
3
The following example code illustrates....
set.seed(18)
dta <- data.frame(var1=factor(c("A", "A", "B", "B", "B", "B", "C", "C", "C")),
var2=c(1,2,1,2,3,4,1,2,3),
var3=round(runif(9,1,10),1),
plotorder=9:1)
dta
windows(3,3)
dotchart(dta$var3[order(dta$var1, -dta$var2)], groups=dta$var1,
labels=dta$var2[order(dta$var1, -dta$var2)], cex=.75,
gcolor=c("blue", "red", "dark green"),
col=c(rep("blue",2), rep("red",4), rep("dark green",3)),
axes=NULL)
Well, the more "lattice-like" version of this would be
dta$var2fac <- factor(dta$var2, levels = rev(sort(unique(dta$var2))))
dotplot(var2fac ~ var3 | var1, data=dta, groups=var1,
col=c("blue", "red", "dark green"),
layout = c(1, 3), as.table = TRUE,
scales=list(y = list(relation = "sliced")))
But if you really want the dotchart()-like output, you can try
dta$var12fac <- with(dta, interaction(var2fac, factor(var1, levels =
rev(levels(var1)))))
dta$var12fac <- droplevels(dta$var12fac)
lab <- substring(levels(dta$var12fac), 1, 1)
dotplot(var12fac ~ var3,
data = dta, groups=var1,
col=c("blue", "red", "dark green"),
scales = list(y = list(labels = lab,
col = rep(c("dark green", "red", "blue"),
c(3, 4, 2)))),
ylab = list(label = c("C", "B", "A"),
y = c(3, 7, 9) / 9.2,
rot = 0, col = c("dark green", "red", "blue")))
-Deepayan