facet_wrap 的 R ggplotly:所有绘图的轴刻度大小不变
R ggplotly with facet_wrap : axis tick size not changing for all plots
我需要使用 ggplotly 来使用 facet_wrap 创建以下图。一切正常,唯一的问题是调整轴刻度标签的大小仅适用于左侧图!
任何想法如何解决这一问题?我特意放了一个小得离谱的尺寸来指出区别。
提前致谢。
library(ggplot2)
library(plotly)
data <- data.frame(group = c('groupe A', 'groupe A', 'groupe A', 'groupe A',
'groupe B', 'groupe B', 'groupe B', 'groupe B'),
level = c('book', 'cd', 'book', 'cd', 'book', 'cd', 'book', 'cd'),
type = c('with', 'with', 'without', 'without',
'with', 'with', 'without', 'without'),
values = c(6,0, 12, 4, 7, 11, 13, 5))
ggplotly(
ggplot(data) +
geom_bar(aes(x = level, y = values, fill = type), stat = "identity", position = "dodge") +
geom_text(aes(x = level, y = values+0.5, fill = type, label = values),
position = position_dodge(width = 1), size = 3) +
scale_fill_manual(values = c(rgb(31, 119, 180, maxColorValue = 255), rgb(59, 159, 255, maxColorValue = 255))) +
theme_bw() +
theme(axis.title = element_blank(),
legend.title = element_blank(),
axis.line = element_blank(),
panel.border = element_rect(color = "black", fill = NA, size = 0.5)
) +
facet_wrap(~group)
) %>%
layout(
showlegend = TRUE,
legend = list(orientation = "h", y = -0.1, x = 0.3),
xaxis = list(tickfont = list(size = 5))
)
嗯,我找到了答案。最好在ggplot主题中提及大小:
ggplotly(
ggplot(data) +
geom_bar(aes(x = level, y = values, fill = type), stat = "identity", position = "dodge") +
geom_text(aes(x = level, y = values+0.5, fill = type, label = values),
position = position_dodge(width = 1), size = 3) +
scale_fill_manual(values = c(rgb(31, 119, 180, maxColorValue = 255), rgb(59, 159, 255, maxColorValue = 255))) +
theme_bw() +
theme(axis.title = element_blank(),
legend.title = element_blank(),
axis.line = element_blank(),
axis.text.x = element_text(size = 5),
panel.border = element_rect(color = "black", fill = NA, size = 0.5)
) +
facet_wrap(~group)
)
我需要使用 ggplotly 来使用 facet_wrap 创建以下图。一切正常,唯一的问题是调整轴刻度标签的大小仅适用于左侧图! 任何想法如何解决这一问题?我特意放了一个小得离谱的尺寸来指出区别。
提前致谢。
library(ggplot2)
library(plotly)
data <- data.frame(group = c('groupe A', 'groupe A', 'groupe A', 'groupe A',
'groupe B', 'groupe B', 'groupe B', 'groupe B'),
level = c('book', 'cd', 'book', 'cd', 'book', 'cd', 'book', 'cd'),
type = c('with', 'with', 'without', 'without',
'with', 'with', 'without', 'without'),
values = c(6,0, 12, 4, 7, 11, 13, 5))
ggplotly(
ggplot(data) +
geom_bar(aes(x = level, y = values, fill = type), stat = "identity", position = "dodge") +
geom_text(aes(x = level, y = values+0.5, fill = type, label = values),
position = position_dodge(width = 1), size = 3) +
scale_fill_manual(values = c(rgb(31, 119, 180, maxColorValue = 255), rgb(59, 159, 255, maxColorValue = 255))) +
theme_bw() +
theme(axis.title = element_blank(),
legend.title = element_blank(),
axis.line = element_blank(),
panel.border = element_rect(color = "black", fill = NA, size = 0.5)
) +
facet_wrap(~group)
) %>%
layout(
showlegend = TRUE,
legend = list(orientation = "h", y = -0.1, x = 0.3),
xaxis = list(tickfont = list(size = 5))
)
嗯,我找到了答案。最好在ggplot主题中提及大小:
ggplotly(
ggplot(data) +
geom_bar(aes(x = level, y = values, fill = type), stat = "identity", position = "dodge") +
geom_text(aes(x = level, y = values+0.5, fill = type, label = values),
position = position_dodge(width = 1), size = 3) +
scale_fill_manual(values = c(rgb(31, 119, 180, maxColorValue = 255), rgb(59, 159, 255, maxColorValue = 255))) +
theme_bw() +
theme(axis.title = element_blank(),
legend.title = element_blank(),
axis.line = element_blank(),
axis.text.x = element_text(size = 5),
panel.border = element_rect(color = "black", fill = NA, size = 0.5)
) +
facet_wrap(~group)
)