 # Bug of the plot generated by R code

#1

Hi all,

Here is a problem about the plot generated by the R code, as you can see from the picture, the equation should be y=-824+1608, "C()" should not be included. I already re-install the R and R studio, it still happened. Below is my code:
.geom_text(aes(x=-Inf,y=Inf,vjust=3,hjust=-0.2,label=as.character(as.expression(eq))),size=3.75,color=ul_cols('dark blue'),parse=TRUE)+
theme_ul()+

#2

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

install.packages("reprex")


If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")


For pointers specific to the community site, check out the reprex FAQ, linked to below.

#3

You may find something here useful, but yes, posting a reprex makes it much easier for people to help.

latex2exp::TeX Converts a LaTeX string to a plotmath expression.

library(ggplot2)
library(latex2exp)

c. <- -824
m. <- 1608
r2. <- 0.6
eq <- TeX(paste0("$y = ", c., " + ", m., "\\cdot x, r^2 = ", r2., "$"))

ggplot() +
geom_text() +
annotate(
"text",
label = eq,
x = 4,
y = 30,
size = 5,
colour = "darkblue"
) Created on 2019-01-11 by the reprex package (v0.2.1)

closed #5

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.