Graphics, Figures & Tablesggplot2 fails to compile

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Mike Poletika
Posts: 1
Joined: Wed Nov 05, 2014 5:03 pm

ggplot2 fails to compile

Post by Mike Poletika »

Hello,

I have a series of ggplots that successfully compile into my pdf, and two that do not. The code is identical among the different plots, except for the directories and file names. I get this error message: Error: unexpected '@' in "@". If someone could give me an idea of what I can do to solve this problem, I'd greatly appreciate it. I'm very new to LaTeX, so a simple explanation would be great.

Thanks,

Mike

This one works:

Code: Select all

<<echo=FALSE, fig=TRUE>>=

library(foreign)
library(ggplot2)

#read tables in 
school1 <- read.dta("C:/Users/Mike Poletika/Desktop/WFF SQM/INDIANAPOLIS/Report/Data/Datasets/schoolidA425/indianapolis_all.dta")

ggplot(school1, aes(growth, attainment))+
  geom_point(aes(colour = yrnstr), size = 3)+
  scale_x_continuous(limits=c(-1.35, 1.35))+
  scale_y_continuous(limits=c(-1.35, 1.35))+
  xlab("Growth")+
  ylab("Attainment")+
  theme(legend.position="bottom")

@
This one doesn't work:

Code: Select all

<<echo=FALSE, results=tex>>=
#Walton VAM Report#

library(foreign)
library(ggplot2)

#read tables in 
allschools <- read.dta("C:/Users/Mike Poletika/Desktop/WFF SQM/INDIANAPOLIS/Report/indianapolis_vam_all.dta")

ggplot(allschools, aes(growth, achievement))+
  geom_point(aes(colour = type), size = 3)+
  scale_x_continuous(limits=c(-1.35, 1.35))+
  scale_y_continuous(limits=c(-1.35, 1.35))+
  xlab("Growth")+
  ylab("Attainment")+
  theme(legend.position="bottom")


@

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

ggplot2 fails to compile

Post by Johannes_B »

Hi and welcome,

not sure if anybody can be of any help here. We are a forum all around TeX and friends, a typesetting system to produce documents of high quality.

You can plot your data sets with LaTeX as well, have a look pgfplots to see some examples.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

ggplot2 fails to compile

Post by Stefan Kottwitz »

Hi Mike,

welcome to the forum! ggplot2 is plotting for R, LaTeX just imports the result.

You could directly plot within LaTeX, also large exported data files, have a look at http://pgfplots.net to see some examples and into the pgfplots manual. With this, some of us could provide help.

Also with any LaTeX related questions, of course. :)

Stefan
LaTeX.org admin
Post Reply