如何为条形图着色&旋转echarts4r中的轴标签

发布于 2025-02-01 17:33:10 字数 416 浏览 2 评论 0原文

我有基本的DF,我正在尝试为每个栏添加不同的颜色。根据E_Color文档,我们需要提供颜色的向量,但它不起作用,我只从矢量中获得一种颜色。此外,我想旋转45dg x轴标签,但尚未找到任何解决方案。这两个主题的任何帮助都非常感谢。

谢谢
亚当

df <- data.frame(
  x = c('AAA','BBB','CCC','DDD','EEE','FFF','GGG'),
  y = c(10,20,30,40,50,60,70)
  )

my_colors <- brewer.pal(7, "GnBu")

df %>% e_chart(x) %>% e_bar(y) %>% e_color(my_colors) %>% e_x_axis(label = list(rotate = 45))

I have basic df and I'm trying to add different color for each bar. According to e_color doc we need to provide a vector of colors but it doesn't work, I'm getting only one color from the vector. Additionally I'd like to rotate by 45dg x axis label but haven't found any solution yet. Any help with both topics much appreciated.

Thanks
Adam

df <- data.frame(
  x = c('AAA','BBB','CCC','DDD','EEE','FFF','GGG'),
  y = c(10,20,30,40,50,60,70)
  )

my_colors <- brewer.pal(7, "GnBu")

df %>% e_chart(x) %>% e_bar(y) %>% e_color(my_colors) %>% e_x_axis(label = list(rotate = 45))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

随风而去 2025-02-08 17:33:10

首先,您需要将颜色分配给名为颜色的数据框架。然后,您可以使用e_add“ itemStyle”添加它们。要旋转标签,您应该使用axislabel像这样:

library(echarts4r)
library(RColorBrewer)
my_colors <- brewer.pal(7, "GnBu")

df$color <- my_colors

df %>% 
  e_chart(x) %>% 
  e_bar(y) %>% 
  e_add("itemStyle", color) %>%
  e_x_axis(axisLabel = list(rotate = 45))

output:

“在此处输入图像说明”

First of all you need to assign your colors to your data frame named color. Then you can add them by using e_add with "itemStyle". To rotate your labels you should use axisLabel like this:

library(echarts4r)
library(RColorBrewer)
my_colors <- brewer.pal(7, "GnBu")

df$color <- my_colors

df %>% 
  e_chart(x) %>% 
  e_bar(y) %>% 
  e_add("itemStyle", color) %>%
  e_x_axis(axisLabel = list(rotate = 45))

Output:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文