[英]How do you increase the space between the axis labels and axis titles in R using functions ggplot() and plot_ly?
似乎每当我使用包plotly
在 R 中创建图形时,轴标题总是覆盖轴标签。 我现在有 2 个图表发生这种情况。 我应该使用什么代码来使用plot_ly()
和ggplot()
增加轴标题和标签之间的空间? 以及如何确保图例在 Plot 1 中可见而不被切断?
以前的 StackOverflow 问题给出了不同的代码结构方法,但它们似乎不适用于我的代码。
情节 1:
plot <- ggplot(dat, aes(x=HeightUnderCWD, y=GrassHeight))+ geom_point()+ labs(x = "Height under CWD (cm)", y = "Grass Height (cm)")+ theme(text=element_text(size=20, family="Arial"))+ stat_smooth(method = "lm",formula = y ~ x,se = FALSE, color='Darkgreen')+ stat_smooth(aes(x = HeightUnderCWD, y = 7, linetype = "Linear Fit"), method = "lm", formula = y ~ x, se = FALSE,size = 1,color='lightgreen') ggplotly(plot)
情节 2:
p<-plot_ly(y = GrassHeight+1, color = CWDPosition,type = "box",colors = "Set1")%>% layout(xaxis = x, yaxis = y, font = f)
对于plot_ly
,不确定它是最佳答案,但可能是由于左边距太小:
plot_ly(type="box") %>%
layout(margin = list(l=25, r=50, b=50, t=50, pad=0),
yaxis=list(title="GrassHeight")) %>%
add_trace(y = ~rnorm(50, 0)) %>%
add_trace(y = ~rnorm(50, 1))
plot_ly(type="box") %>%
layout(margin = list(l=100, r=50, b=50, t=50, pad=0),
yaxis=list(title="GrassHeight")) %>%
add_trace(y = ~rnorm(50, 0)) %>%
add_trace(y = ~rnorm(50, 1))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.