0

I'm trying to plot some data, one of my experimental groups is named SiO₂. I load a .txt datasheet using read.table and then I change the col names with colnames()<-.

colnames(cells_df2) <- c("ID","Ctrl","SiO\u2082","pSLG","fSLG")

Here is a subset of my data.

head(cells_df2)
ID     Ctrl  SiO2     pSLG     fSLG
1  1  5.68565  9.48 14.77580 33.04500
2  2  6.79996 32.00 14.35580 33.04500
3  3 21.77180  8.14 16.49780  7.61765
4  4 16.30750  8.14  1.87977  7.61765
5  5 11.16920 19.20  5.54189 28.47990
6  6 11.31430  8.26 15.59490 28.47990

Then, I gathered of this data.frame

Cells_tidy3<-gather(cells_df2,"group","ym",-ID)
  ID group       ym
1  1  Ctrl  5.68565
2  2  Ctrl  6.79996
3  3  Ctrl 21.77180
4  4  Ctrl 16.30750
5  5  Ctrl 11.16920
6  6  Ctrl 11.31430

Finally I plot them

ggboxplot(Cells_tidy3,"group","ym")

enter image description here

I have tried to use expression, parse, stringi package with scarce results.

If I ask for capabilities()

jpeg         png        tiff       tcltk         X11        aqua    http/ftp 

TRUE        TRUE        TRUE        TRUE       FALSE       FALSE`    TRUE 

sockets      libxml        fifo      cledit       iconv         NLS   profmem

TRUE        TRUE        TRUE        TRUE        TRUE        TRUE        TRUE

cairo         ICU long.double     libcurl 

TRUE        TRUE        TRUE        TRUE 

Then I tried:

png()
ggplot(az, aes(x = "SiO\u2082", y = value)) + 
geom_boxplot() +
xlab("")
dev.off()

Which lead to this graph

enter image description here

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66

1 Answers1

0

The following works. It uses ggplot followed by geom_boxplot, not ggpubr::ggboxplot.

library(ggplot2)

az <- subset(iris[5:4], Species == "virginica")
az[[1]] <- droplevels(az[[1]])
names(az) <-c("SiO\u2082","value")

ggplot(az, aes(x = "SiO\u2082", y = value)) + 
  geom_boxplot() +
  xlab("")

enter image description here

With package ggpubr, the problem is how you gathered the data. The column "value" became a column with value of the previous column name in az, which was "ciao".

library(tidyr)
library(ggpubr)

azz <- az %>% gather(group, key, -value)
ggboxplot(azz, x = "group", y = "value")

enter image description here

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
  • @pietroesposito No, not as a comment, in the question, please. And see the edit with `ggpubr`. – Rui Barradas Dec 07 '19 at 17:47
  • If I use your codes both the one with ggplot and ggpubr I obtain SiO□ – pietro esposito Dec 07 '19 at 18:01
  • @pietroesposito As you can see, both plots display the subscript correctly so there must be something with your system. What does `capabilities()` return? And if you write to a device with, say, `png()` before the plot and `dev.off()` right after, what's in the graphic file? – Rui Barradas Dec 07 '19 at 18:48
  • I re-edit my question with the information you asked for. – pietro esposito Dec 08 '19 at 13:52
  • 1
    @pietroesposito This seems to be a system thing. Try installing X11? Also, see if these posts can help: [R-bloggers](https://www.r-bloggers.com/unicode-symbols-in-r/), SO [1](https://stackoverflow.com/questions/35682707/r-plots-some-unicode-characters-but-not-others) or [2](https://stackoverflow.com/questions/5886018/using-unicode-dingbat-like-glyphs-in-r-graphics-across-devices-platforms-e). – Rui Barradas Dec 08 '19 at 17:05
  • unfortunately I didn't menage to install X11, I looked on the web and I didn't find anything – pietro esposito Dec 09 '19 at 14:30