【发布时间】:2019-08-12 10:21:00
【问题描述】:
我必须将ggplot 转换为plotly。当然,最简单的方法似乎是使用ggploty,但字体大小会发生变化。恢复轴标签和标题的合适大小没问题,但我不知道如何为数据标签做到这一点?有任何想法吗?我更喜欢保留ggplot 并用ggplotly 包裹它(还有许多其他情节)。
我尝试了布局中的字体,但没有成功:
library(ggplot2)
library(plotly)
tbl <- data.frame(
indicateur = c("freq1", "freq2", "freq3" ),
valeur = c(44, 78, 84)
)
ggplotly(
ggplot(tbl) +
geom_bar(aes(x = indicateur, y = valeur), stat = 'identity', fill = rgb(31, 119, 180, maxColorValue = 255)) +
geom_text(aes(x = indicateur, y = valeur, label = valeur), vjust = -0.5) +
ylim(0, max(tbl$valeur)*1.1) +
labs(x = "", y = "", title = "simple counting") +
theme_bw() +
theme(
axis.line = element_blank(),
panel.border = element_blank(),
plot.title = element_text(hjust = 0.5)
)
) %>%
layout(
showlegend = FALSE,
textfont = list(size = 5),
titlefont = list(size = 12),
xaxis = list(tickfont = list(size = 9))
)
提前感谢您的帮助。
【问题讨论】: