Color in qplot
The plot does not have colors. I would appreciate help to modify the following script. I use the latest RStudion and R versions. Here is the script I used. Thanks
\documentclass{article} \usepackage{alltt} \begin{document}
<<>>=
library(ggplot2)
library(RColorBrewer)
attach(mpg)
qplot(displ,hwy,data=mpg,color=factor(cyl))
@ \end{document}
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Josh Paulson on 10 Aug, 2012 02:36 PM
Hello,
Take a look at the following Knowledge Base article. This should give you some direction on how to get help with this:
http://support.rstudio.org/help/kb/troubleshooting/getting-help-with-r
Josh
Josh Paulson closed this discussion on 10 Aug, 2012 02:36 PM.
chettyvk re-opened this discussion on 10 Aug, 2012 02:47 PM
3 Posted by chettyvk on 10 Aug, 2012 02:47 PM
Thanks Josh. It works perfectly in R and also in Markdown. The problem
occurs only when use knitr and compile the PDF. SO does this not suggest it
is an RStudio related issue? I have also tried some suggestions in the
discussion such as "dev.off()" several times. It does not help. I think it
has something to do with opening the right plotting device.
Thanks.
Chetty
Support Staff 4 Posted by Josh Paulson on 10 Aug, 2012 04:31 PM
Chetty,
I'm actually unable to reproduce this problem using your exact document and compiling with knitr. Can you add the following to the R code chunk in your document and attach the pdf that is created:
Josh
Support Staff 5 Posted by Josh Paulson on 10 Aug, 2012 04:38 PM
See the attached file for what I'm looking for.
6 Posted by chettyvk on 10 Aug, 2012 04:48 PM
Thanks Josh. I have attached the pdf.
Chetty
Support Staff 7 Posted by Josh Paulson on 10 Aug, 2012 06:08 PM
Chetty,
Thanks for uploading this and there is definitely something strange going on here. If you look at your plot, it actually plotted the following:
This doesn't show up anywhere in your code, but is clearly in your pdf. This explains why the color is void from the plot since it is the wrong plot entirely. I honestly don't know what would be doing this, but am fairly certain it is not RStudio. We're not doing anything other than the following (you could try replicating from another R interface):
None of this (as far as I know) would cause the behavior that you are seeing. Nevertheless, it would be good to get to the bottom of what is going wrong. Can you try a more simple plot such running the following in a new Sweave document:
Also can you think of any other reason why your session might be injecting code from somewhere else? Does this happen inside/outside a RStudio project? Have you customized any options for latex or markdown?
http://www.rstudio.org/docs/authoring/latex_program
http://www.rstudio.org/docs/authoring/markdown_custom_rendering
Josh
8 Posted by chettyvk on 11 Aug, 2012 01:30 AM
Thanks Josh. I tired in another PC. I got the same outcome. Then I tried
the simple plot "plot(pressure,col="red") and it worked Then I tried my
qplot. This time it worked correctly ( See the attached output).
I am not an expert. My guess is it has something to do with closing and
opening devices.
Now it works in all my computers.
Thanks again for your help.
Chetty
Support Staff 9 Posted by Josh Paulson on 11 Aug, 2012 03:53 AM
Chetty,
Glad to hear that it's working now and my guess is that there was some caching involved. Perhaps somehow a former plot was being used rather than the current.
Josh
Josh Paulson closed this discussion on 11 Aug, 2012 03:53 AM.