Can't get 'output.type = "LaTeX"' to work

Create issue
Issue #14 resolved
Former user created an issue

When I try to produce a LaTeX-compatible regression equation, I receive an error.

Here's a MWE:

# Preliminary stuff:
library(pwt9)
library(reshape)
library(ggplot2)
library(ggpmisc)

pwtorg <- pwt9.0
rawdat <- subset(pwtorg,
                 subset=year==1960 | year==2014,
                 select = c(isocode,year,rgdpo,pop))
rawdat$rgdpopc <- rawdat$rgdpo/rawdat$pop # GDP per capita
rawdatmelt <- melt(rawdat, id = c("isocode","year")) # 'melt' data along country, year
rawdatcast <- cast(rawdatmelt, isocode ~ variable + year) # reshape to wide format

# Compute average growth rage
rawdatcast$cagr <- ((rawdatcast$rgdpopc_2014/rawdatcast$rgdpopc_1960)^(1/54)-1)*100
# US GDP per capita in 1960
rgdppcUS60 <- as.numeric(subset(rawdatcast, subset=isocode=="USA", select = rgdpopc_1960))
# Express each country's 1960 GDPpC relative to US':
rawdatcast$rgdppc60relUS <- (rawdatcast$rgdpopc_1960/rgdppcUS60)*100

# Actual plot:
p <- ggplot(data = rawdatcast, aes(x = rgdppc60relUS, y = cagr)) +
  geom_point(na.rm = TRUE) +
  geom_text(aes(label = isocode), size = 2.5, hjust = -.1, vjust = 0, nudge_x = 0.1, check_overlap = TRUE,na.rm = TRUE) +
  scale_x_continuous(
    name = "Reales BIP pro Kopf 1960 relativ zu US (in %)"
  ) +
  scale_y_continuous(
    name = "Durchschn. jährl. Wachstumsr. reales BIP 1960-2014 (in %)"
  ) +
  geom_smooth(method = "lm", colour = "black", se = FALSE, na.rm = TRUE) +
  theme_bw()

p + stat_poly_eq(aes(label = ..eq.label..), formula = y ~ x, 
                 parse = TRUE, na.rm = TRUE)

p + stat_poly_eq(aes(label = ..eq.label..), formula = y ~ x, 
                 output.type = "LaTeX", parse = TRUE, na.rm = TRUE)

This produces the error

Error in parse(text = as.character(lab)) : <text>:1:30: unexpected symbol
1: italic(y)~`=`~2.4 - 0.00134  x
                                 ^

Am I doing something wrong?

(P.S. Thank you writing ggpmisc!)

Comments (4)

  1. Pedro J. Aphalo repo owner

    Sorry! I missed this issue until now. Thanks for reporting this. I will investigate this problem and try to get it resolved soon. Many thanks for reporting it!

  2. Pedro J. Aphalo repo owner

    I now realize that the cause of the error is setting parse = TRUE. Parsing is needed and possible only in the case of character strings to be interpreted as R expressions. Now this is explained in the documentation.

  3. Log in to comment