Error in eval(expr, envir, enclos) : object 'dx' not foundplotfunc <- function(dx, dy, dxlab, dylab, outFile) { + p1 <- ggplot ( dat, aes(x= dx, y=dy, colour=mm.state) )+ + geom_text(aes(label=stcode), size=8, vjust=0)+ + xlab(dxlab)+ + ylab(dylab)+ + theme(text = element_text(size=25,face = "bold"), + axis.text.x = element_text(hjust=1, face="bold"), + axis.text.y = element_text(hjust=1, face="bold"), + axis.title.y = element_text(face="bold"), + axis.title.x = element_text( vjust=1, face="bold"), + legend.position="none" ) + print (p1) + ggsave(file=outFile, width=15, height=7) + } > > > plotfunc(dat$obtmj_p, dat$prevmj_p, + "Fairly/Very Easy to Obtain Marijuana","Past Year Marijuana Use","MrjUseAccess.png") Error in eval(expr, envir, enclos) : object 'dx' not found
--
--
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
Error in grDevices::png(..., width = width, height = height, res = dpi, : unable to start png() device In addition: Warning messages: 1: In grDevices::png(..., width = width, height = height, res = dpi, : Unable to open file 'MrjUseAccess.png' for writing 2: In grDevices::png(..., width = width, height = height, res = dpi, : opening device failed
p1 <- ggplot ( dat, aes(x= dx, y=dy, colour=mm.state), environment = parent.env() )+
Error in parent.env() : argument "env" is missing, with no default
Thank you so much for coming up with the alternative solutions and explaining the code to me.
Your method 2 is the one I am interested in. My data set will remain the same but the variable will change.
It seems that if I use the aes_string () I don't need to use the environment=environment as I have used in my following revised code (also ran successfully) with tips and resources sent by Brandon.
regards,
Pradip Muhuri
############
plotfunc <- function(dx, dy, dxlab, dylab, outFile) {
p1 <- ggplot ( data, aes(x= dx, y=dy, colour=mm.state), environment=environment () )+
geom_text(aes(label=stcode), size=8, vjust=0)+
xlab(dxlab)+
ylab(dylab)+
theme(text = element_text(size=25,face = "bold"),
axis.text.x = element_text(hjust=1, face="bold"),
axis.text.y = element_text(hjust=1, face="bold"),
axis.title.y = element_text(face="bold"),
axis.title.x = element_text( vjust=1, face="bold"),
legend.position="none" )
print (p1)
ggsave(file=outFile, width=11, height=7)
}
plotfunc(data$obtmj_p, data$prevmj_p,
"Fairly/Very Easy to Obtain Marijuana",
"Past Year Marijuana Use",
'MrjUseAccess.png')
________________________________________
From: Dennis Murphy [djm...@gmail.com]
Sent: Saturday, January 26, 2013 4:01 PM