qplot and commandArgs problem

27 views
Skip to first unread message

scott smith

unread,
Oct 15, 2012, 9:43:05 AM10/15/12
to ggp...@googlegroups.com
Hi,

I'm trying to write a simple .R script to produce plots from a .csv file specified in the command line.

for example, the following will plot LSS vs RSS from the scott_dose.csv file:

scott.smith@cougar:/home/scott.smith {31} Rscript Rtest.R scott_dose.csv LSS RSS

and the .R script is:

library(ggplot2)
args <- commandArgs(TRUE)

data<-data.frame(read.csv(args[1]))
attach(data)

x <- args[1]
y <- args[2]
z <- args[3]

x
y
z


qplot(y,z)

ggsave("~/tmp/RTest.png")

browseURL("~/tmp/RTest.png")

which produces a graph output, but with no data plotted:

scott.smith@cougar:/home/scott.smith {31} Rscript Rtest.R scott_dose.csv LSS RSS
Loading required package: methods

[1] "scott_dose.csv"
[1] "LSS"
[1] "RSS"
Saving 7 x 7 in image

Basically my "y" and "z" variables from commandArgs aren't being picked up by qplot. I'm sure it is something very simple, but I'm a relative beginner to R.

thanks, Scott

Ben Bond-Lamberty

unread,
Oct 15, 2012, 9:48:44 AM10/15/12
to scott smith, ggp...@googlegroups.com
Probably change your script to

p <- qplot( y, z )
ggsave("~/tmp/RTest.png", plot=p)

qplot doesn't produce any output inside of a script without being
explicitly print'ed.

Ben
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
Message has been deleted

scott smith

unread,
Oct 15, 2012, 10:02:28 AM10/15/12
to ggp...@googlegroups.com, scott smith
Hi Ben,

Thanks - but unfortunately no change....image attached for reference....exactly the same as my original script.


library(ggplot2)
args <- commandArgs(TRUE)

data<-data.frame(read.csv(args[1]))
attach(data)

x <- args[1]
y <- args[2]
z <- args[3]

x
y
z

p <- qplot(y,z)

ggsave("~/tmp/RTest.png",plot=p)

browseURL("~/tmp/RTest.png")



thanks,
Scott
RTest.png

Brandon Hurr

unread,
Oct 15, 2012, 10:04:27 AM10/15/12
to scott smith, ggp...@googlegroups.com
The picture looks fine to me... RSS on the y axis, LSS on the x axis... scatterplot. 

scott smith

unread,
Oct 15, 2012, 10:07:51 AM10/15/12
to ggp...@googlegroups.com, scott smith
oops, thats how the graph SHOULD look when I do a qplot(LSS,RSS)!!

attached is the empty graph...

Scott
RTest.png

Brandon Hurr

unread,
Oct 15, 2012, 10:11:19 AM10/15/12
to scott smith, ggp...@googlegroups.com
I wouldn't say that's empty. There is clearly at least one point located at z,y, which makes me think that it's an issue with ""'s. 

I think it is plotting text versus text instead of your values. I believe you need to use ggplot(data=data, aes_string(x=y, y=z))+geom_point()

scott smith

unread,
Oct 15, 2012, 10:16:10 AM10/15/12
to ggp...@googlegroups.com, scott smith
Fantastic Brandon thanks!

Works perfectly.

Was trying to be quick and test it out with qplot.......should have plunged straight into ggplot

thanks,
Scott
Reply all
Reply to author
Forward
0 new messages