bgroup does not render properly on ggplot - r

The results of bgroup from plotmath do not seem to render properly as a ggplot2 annotation. For example ...
library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
annotate("text", x=2.5, y=25, label="bgroup('(',atop(x,y),')')", parse=TRUE) +
annotate("text", x=3.5, y=25, label="group('(',atop(x,y),')')", parse=TRUE)
... produces the following graph for me ...
Note how the bgroup rendering on the left does not have large parentheses like I would expect (and worked in some previous version of R), whereas the reqular group rendering to the right does seem to work.
Am I missing a font? Something else?
I am using R 4.2.2 and ggplot2 3.4.0.
EDITS:
The code above worked properly in R versions 4.0.5, 4.1.0, 4.1.2, and 4.2.0 (and 3.6.3 according to Jamie in the comments .. but not on Linux according to an answer on R-help).
The issue does not seem related to ggplot2 as the same problem occurs with base graphics.
The same issue occurs with R version 4.2.2 whether the code is run in RStudio or the RGui.
The same issue occurs (in R version 4.2.2) when the plot is directed to a PNG but not when it is directed to a PDF.
plot(0,xlim=c(0,1),ylim=c(0,1))
text(0.5,0.5,expression(bgroup('(',atop(x,y),')')))

It's working fine for me on Linux; I guess you guys are all using Windows?
Note that "rendering" strongly depends on the graphics device.
What is your .Device {after plotting}?
I suggest a Windows graphapp font problem, similar to the one just fixed yesterday, also Windows-only:
https://bugs.r-project.org/show_bug.cgi?id=18440

Related

how do I fix plot problem with R in Jupyter notebook? [duplicate]

My R was installed in a conda environment on Ubuntu 20.04.1 VM.
I was searching for this problem when i found this thread. I too am using RStudio from Anaconda, on Debian 10.0 (buster).
Try
par(family = "Arial")
or whichever font name before calling plot(). It worked for me.
Update > I still had problems with ggplot2 plots not displaying labels, like above. I tried the workaround of using showtext() instead of regular text rendering.
install.packages("showtext")
After it was installed,
library(showtext)
to load the library. Then simply call
showtext_auto()
followed by the ggplot(.....) + ... + etc. function and text was rendered alright within the plot. I did not load specific fonts using font_add(). Maybe because previously 'Arial' was loaded with par()

Text does not show properly in R plot

My R was installed in a conda environment on Ubuntu 20.04.1 VM.
I was searching for this problem when i found this thread. I too am using RStudio from Anaconda, on Debian 10.0 (buster).
Try
par(family = "Arial")
or whichever font name before calling plot(). It worked for me.
Update > I still had problems with ggplot2 plots not displaying labels, like above. I tried the workaround of using showtext() instead of regular text rendering.
install.packages("showtext")
After it was installed,
library(showtext)
to load the library. Then simply call
showtext_auto()
followed by the ggplot(.....) + ... + etc. function and text was rendered alright within the plot. I did not load specific fonts using font_add(). Maybe because previously 'Arial' was loaded with par()

Error: ScalesList was built with an incompatible version of ggproto

I'm doing a presentation in slidfy, using the deckjs framework.
Everything was ok, but suddenly this chunk of code:
ggplot(cars, aes(x = speed, y = dist)) + geom_point(color = 'red') + stat_smooth(method = "lm", formula = y ~ x, size = 0.5, se = F)
stopped working and shows this error instead:
## Error: ScalesList was built with an incompatible version of ggproto.
## Please reinstall the package that provides this extension.
The code works perfectly when executed from source or console... But it doesn't work anymore from the R markdown. The function that fails is the stat_smooth(). The rest visualizes ok if executed without the smooth.
Here and here a similar error is reported, and the solution offered is to reinstall ggplot and the packages from github, but I'm not sure which packages should I install, and, besides, the code only fails from Rmarkdown, and not when executed from console or source.
Thanks
I had a similar problem in RMarkdown after updating ggplot2. I was loading a workspace with plots created with the older version of ggplot2. The solution was to recreate that workspace with the updated version, and now RMarkdown works.
This is very strange; now things are back to normal.
I did what #baptiste suggested, and the R source code just worked ok.
After that, I knitted the Rmarkdown again and the error had disappeared!
in Feb 2017 the same error was resolved by re-installing all the packages (RStudio - Tools - Check for package updates)
I had similar problem with geom_tufteboxplot . I first updated ggplot2 & ggthemes package, then detached all ggplot related packages and reloaded them. It worked for me.

no more geom_label( ) in ggplot2 1.01?

I was following this ggplot2 docs try to reproduce text labels with geom_label. But I got an error message,
"could not find function geom_label"
. ?geom_label also says no such function. I checked on another two computers and got the same error message. All are with R 3.22, in RStudio 0.99.489 or in pure R command. ggplot2 is version 1.01 installed with install.packages(ggplot2).I did not find a clue from Google. So it seems that geom_label has been removed from the latest ggplot2 before any documentation can be made.
My question is: what is used to replace geom_label, which produces nice text labels in a boxed background?
Here is the code from the ggplot2 docs that suppose to produce the figure below.
p <- ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars)))
p + geom_label()
geom_label was implemented on 2015-07-24. The current version on CRAN (1.0.1) was published on 2015-03-17. You'll need to install the development version from GitHub if you want to use geom_label or wait until it is uploaded to CRAN (which might take a while).

Right to left languages support in R, using Mac

I am wondering if there is anyway to support right-to-left languages in R while using Mac
For instance suppose the following code:
x <- data.frame(a=runif(10),b=runif(10))
ggplot(x, aes(a,b)) + geom_point() + xlab("سلام")
Here is the result:
Here I tried to change the x-label as a Persian/Arabic word (سلام = Hello). While displayed correctly in the code (using R-Studio), in the graph the characters of سلام are displayed in the reverse order (left-to-right).
Also the linkage between two consecutive letters (i.e. س connected to ل would be سل) is broken.
Do you have any idea how to fix it?
Update
With the answer of #agstudy I found R under Ubuntu is perfectly OK. However I have no idea how to solve the problem in Mac (OS X 10.9.1) having updated version of R and R-Studio
It works fine for me. I just change the size of labels to better show it.
library(ggplot2)
x <- data.frame(a=runif(10),b=runif(10))
ggplot(x, aes(a,b)) +
geom_point()+ xlab('سلام') +
theme( axis.title=element_text(size=100,face="bold"))
I am using :
other attached packages:
[1] ggplot2_0.9.3.1
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Also works fine under :
R version 3.0.3 (2014-03-06)
Platform: x86_64-pc-linux-gnu (64-bit)
I had the same problem with Hebrew letters, and I manage to work around it by reading the label from an Excel file instead of typing it directly into R studio. This method works as long as you don't need to mix letters with numbers, in that case things start to get messy.
for example:
I know this is an old question, but I recently wrote an R package to deal with it. It's a simple R wrapper around some python code, since this problem also occurs when using python in mac. The package reverses the Arabic string and then reconnects the letters correctly using Abdullah Diab's python-arabic-reshaper module.
My package is here.
Abdullah Diab's module (for python) is here.

Resources