Выделение полосы strip.text курсивом с помощью plotly / ggplotly - PullRequest
0 голосов
/ 09 июля 2020

Я пытался использовать ggplot2 и функцию ggplotly из библиотеки "plotly" в R, чтобы создать фасетную сетку с выделенными курсивом метками на оси Y, и просто не могу этого добиться.

Здесь я буду использовать пример фасетной сетки «Свободная ось Y», как написано Plotly: https://plotly.com/ggplot2/facet_grid/

Единственное изменение, которое я внес в этот код, - сделайте полосу текста для обеих осей больше, а текст оси Y выделен курсивом в теме ggplot ().

library(reshape2)
library(ggplot2)
library(plotly)

p <- ggplot(tips, aes(x=total_bill)) + geom_histogram(binwidth=2,colour="white")

# With panels that have the same scaling, but different range (and therefore different physical sizes)
p <- p + facet_grid(sex ~ smoker, scales="free", space="free") +
              theme(strip.text.x=element_text(size=13),
                    strip.text.y=element_text(size=13,face="italic"))

p

fig <- ggplotly(p)

fig

График, созданный ggplot (p), выглядит следующим образом, с метками фасетов оси Y курсивом: ggplot с правильным курсивом

График, созданный ggplotly (fig), выглядит так: ggplotly без курсива

1 Ответ

0 голосов
/ 09 июля 2020

Вы можете изменить данные в p, добавив html теги для курсива

library(reshape2)
library(ggplot2)
library(plotly)

p <- ggplot(tips, aes(x=total_bill)) + geom_histogram(binwidth=2,colour="white")

p <- p + facet_grid(sex ~ smoker, scales="free", space="free") +
    theme(strip.text.x=element_text(size=13),
          strip.text.y=element_text(size=13, face="italic"))

p$data$sex <- paste0("<i>", p$data$sex, "</i>")
fig <- ggplotly(p) 
fig

Created on 2020-07-08 by the пакет реплекс (v0.3.0)

...