#here's how to plot it using plot() and lines()
# (yes, this looks silly, but it's a simplification of
# other data I have)
plot(a$x,a$y)
lines(
x=c(min(a$x),b,max(a$x))
,y=c(min(a$y),c,min(a$y))
)
#here's an attempt to use qplot() & geom_line() to do the same
p=qplot(data=a,x=x,y=y)
p=p+geom_line(
aes(
x=c(min(a$x),b,max(a$x))
,y=c(min(a$y),c,min(a$y))
)
)
print(p)
# Error in data.frame(..., check.names = FALSE) :
# arguments imply differing number of rows: 3, 10
#try with ggplot()
p=ggplot(data=a,aes(x=x,y=y))
p=p+geom_point()
p=p+geom_line(
aes(
x=c(min(a$x),b,max(a$x))
,y=c(min(a$y),c,min(a$y))
)
)
print(p)
# Error in data.frame(..., check.names = FALSE) :
# arguments imply differing number of rows: 3, 10
--
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University
Looking to arrange a meeting? Check my public calendar:
http://tinyurl.com/mikes-public-calendar
~ Certainty is folly... I think. ~
#use names "x" and "y"
a=as.data.frame(cbind(x=1:10,y=c(1:5,5:1)))
p=qplot(data=a,x=x,y=y)
print(p) #works ok
p=p+geom_line(
data=data.frame(
x=c(1,5.5,10)
,y=c(1,2.5,1)
)
)
print(p) #works ok
#use names "iv" & "dv"
a=as.data.frame(cbind(iv=1:10,dv=c(1:5,5:1)))
p=qplot(data=a,x=iv,y=dv)
print(p) #works ok
p=p+geom_line(
data=data.frame(
x=c(1,5.5,10)
,y=c(1,2.5,10)
)
)
print(p) #yields an error
#try ggplot()
p=ggplot(data=a,aes(x=iv,y=dv))+geom_point()
print(p) #works ok
p=p+geom_line(
data=data.frame(
x=c(1,5.5,10)
,y=c(1,2.5,10)
)
)
print(p) #yields an error
a=as.data.frame(cbind(iv=1:10,dv=c(1:5,5:1)))
p=qplot(data=a,x=iv,y=dv)
print(p) #works ok
p=p+geom_line(
data=data.frame(
x=c(1,5.5,10)
,y=c(1,2.5,1)
), mapping=aes(x=x, y=y)
)
print(p) # works
HTH,
baptiste
--
That's a good explanation.
Preferably the mapping shouldn't depend on anything outside of the
plot/layer data. If you save this plot and reload it in another
session, it won't work because it won't have access to a, b, or c. If
I could figure out how to make this an error, I would.
Hadley
Mike