geom_vline and log y axis

134 views
Skip to first unread message

AdrianB

unread,
Feb 28, 2009, 1:07:17 AM2/28/09
to ggplot2
Hi all,

I'm trying to draw vertical lines in a CFD plot which uses log y
axis. The line works no problems with a linear axis but doesn't like
the log transformation. I'm guessing there is an undefined problem for
y=0 and I have tried to limit y >= 1 but it does not seem to produce
the results I had intended.


pm10 <- read.csv("data.csv")
h <- hist(pm10$x, breaks=100, plot=FALSE)

m <- qplot( h.mids,h.counts, data = yframe, geom="line",
xlab="Concentration",
ylab = "Number of Periods where Concentration is > C",
main = "Cumulative Frequency Distribution")
m <- m + geom_vline(xintercept=c(50,70))
m <- m + geom_hline(colour="darkblue", yintercept=c(5,10))
m <- m + ylim(2,365)
m <- m + coord_trans(y ="log10")
m



Is there a better way to draw in the vertical lines?

Cheers

Adrian

AdrianB

unread,
Feb 28, 2009, 1:40:13 AM2/28/09
to ggplot2
Sorry...

My bad cut and paste: there were a couple of lines missing in the
code.


>pm10 <- read.csv("data.csv")
>h <- hist(pm10$x, breaks=100, plot=FALSE)
>h <- hist(pm10, breaks=100, plot=FALSE)
>h$counts <- rev(h$counts)
>h$counts <- cumsum(h$counts)
>h$counts <- rev(h$counts)
>m <- qplot( h.mids,h.counts, data = yframe, geom="line", xlab="Concentration",
> ylab = "Number of Periods where Concentration is > C",
> main = "Cumulative Frequency Distribution")
>m <- m + geom_vline(xintercept=c(50,70))
>m <- m + geom_hline(colour="darkblue", yintercept=c(5,10))
>m <- m + ylim(2,365)
>m <- m + coord_trans(y ="log10")
>m


hadley wickham

unread,
Feb 28, 2009, 10:08:05 AM2/28/09
to AdrianB, ggplot2
Hi Adrian,

Would you mind creating a completely reproducible example? We are
missing data.csv.

Hadley
--
http://had.co.nz/

AdrianB

unread,
Feb 28, 2009, 10:38:47 PM2/28/09
to ggplot2
Ok, I've uploaded data.csv to:

http://groups.google.com.au/group/ggplot2/web/data.csv

I've also cleaned up the code a little better (more cut and past
errors :-( ) and as long as data.csv is in the R working directory the
following code should work cleanly.

Cheers

Adrian


pm10 <- read.csv("data.csv")
h <- hist(pm10$x, breaks=100, plot=FALSE)
h$counts <- rev(h$counts)
h$counts <- cumsum(h$counts)
h$counts <- rev(h$counts)
yframe<- data.frame(h$mids,h$counts)

AdrianB

unread,
Mar 3, 2009, 12:35:44 AM3/3/09
to ggplot2
Hi all,

Just a small update. I've added a plot which shows what is being
produced when I try to use geom_vline with a log y axis.


http://groups.google.com.au/group/ggplot2/web/cfd.png


As a work around I am using geom_line and specifying the points to
plot.

lines <- data.frame(x = c(50,50), y = c(1, 365))
m <- m + geom_line(aes(x=x, y=y), data =
lines,linetype=1,colour="gray20")

lines2 <- data.frame(x = c(70,70), y = c(1, 365))
m <- m + geom_line(aes(x=x, y=y), data =
lines2,linetype=1,colour="gray20")


Regards

Adrian

hadley wickham

unread,
Mar 4, 2009, 11:58:40 PM3/4/09
to AdrianB, ggplot2
Ah ok, yes, this is a known problem and it is on my to do list. You
might find working with geom_segments a little easier for the work
around, but your approach is basically right.

Hadley
--
http://had.co.nz/
Reply all
Reply to author
Forward
0 new messages