网站绘图中的y轴重叠,而ggplotly在

时间:2020-10-29 02:41:50

标签: r ggplot2 r-plotly

我正在尝试使用<Slider BackgroundColor="Aquamarine" Maximum="{Binding SliderMax}" Minimum="0" Value="{Binding SliderStep}" IsEnabled="False" VerticalOptions="EndAndExpand" ></Slider> 包中的IsEnabled="False" 函数将构面图转换为html样式。

一切正常,但y轴重叠。而且我不知道该怎么解决。

可复制的代码如下:

ggplotly()

1 个答案:

答案 0 :(得分:1)

不幸的是,使用n.dodge和check.overlap参数的ggplot2 3.3中包含的新guide_axis()技巧目前不会影响您的ggplotly()输出:https://www.tidyverse.org/blog/2020/03/ggplot2-3-3-0/#rewrite-of-axis-code < / p>

另一种选择是使用带有数字数据的双y轴 ,然后在两个标签之间分割标签,但再次会忽略这一点。

ggplot2的许多功能将不容易转化为交互式的图形可视化。

我能想到的最好的解决方法是调整中断标签的字体大小,并更改刻面的布局,以便为标签留出更多空间(假设在x轴上显示的信息少得多) ):

library(tidyverse)
state <- 1:31 %>% as.character()
disease <- 1:40 %>% as.character()
city <- LETTERS[1:2]
value <- runif(n = 31*40*2)

df <- expand.grid(state = state,
                  disease = disease,
                  city = city) %>% cbind(value)

p <- df %>% 
  ggplot(aes(x = city, y = disease, fill = value)) +
  geom_tile() + 
  scale_fill_gradient(high = '#FF0000', low = 'white') +
  theme(axis.line = element_line(linetype = 'solid')) + 
  theme_classic() +
  scale_x_discrete(expand = c(0,0)) +
  scale_y_discrete(expand = c(0,0)) +
  facet_wrap(vars(state), nrow = 3) +
  theme(axis.text.y = element_text(size = 4))
p

reprex package(v0.3.0)于2020-10-29创建

在转换为绘图可视化效果时,这些设置将保留:

web_p <- ggplotly(p)
web_p