John Kane
unread,Mar 2, 2012, 8:59:57 AM3/2/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ggplot2
I am trying to create a simple dot-plot in ggplot2 with a solid line
from the y-axis to the dot, something I first saw in Cleveland's 1984
book
What I would like is to have the graph start at zero on the x-axis but
leave some space on the right side of the plot area.
I assumed that I should be able to do this with expand() in
scale_x_continuous() but either I'm wrong or just don't understand
what expand() is doing. So far, I see that
scale_x_continuous(expand=c(0,0)) removes the space on the right and
left. but I don't understand how to just get the left only to
disappear.
Any help would be appreciated
Code
#================================================
library(ggplot2)
xx<- structure(list(Food = c("Milk", "Bread", "Potatoes", "Rice"),
Expense = c(25L, 49L, 34L, 15L)), .Names = c("Food", "Expense"
), class = "data.frame", row.names = c(NA, -4L))
xx$Food <- as.factor(xx$Food)
p <- ggplot(xx, aes(Expense, reorder(Food, Expense)))
pa <- p + geom_point(aes(colour=Food)) +
geom_segment(aes(x = 0, xend = Expense,
y = Food, yend = Food,colour=Food)) +
opts(legend.position = "none")
pa # so far so good
p1 <- pa + scale_x_continuous(expand=c(0,0)) # Nope.
#=============================================
sessionInfo
version 2.13.1 (2011-07-08)
Platform: i686-pc-linux-gnu (32-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] grid stats graphics grDevices utils datasets
methods
[8] base
other attached packages:
[1] ggplot2_0.8.9 proto_0.3-9.2 reshape_0.8.4 plyr_1.7