简体   繁体   English

在“R”中制作圆形条形图

[英]Making a Circular Barplot in 'R'

I'm trying to recreate this circular barplot:我正在尝试重新创建这个圆形条形图:

The only difference would be the data, labels and the fact that I want 160 bars on my chart.唯一的区别是数据、标签以及我希望图表上有 160 根柱线这一事实。 I have looked at the code in R Graph Gallery but I am a complete novice and don't understand how to go from what they have to what I want.我已经查看了 R Graph Gallery 中的代码,但我是一个完整的新手,不明白如何从他们拥有的变成我想要的。

Any help in making this barplot or pointing me somewhere that can help me would be greatly appreciated在制作此条形图或将我指向可以帮助我的地方的任何帮助将不胜感激

This is the Data It shows Gross Value Added per hour (£)这是数据它显示增加值每小时(£)

The problem with this kind of question is that, without seeing your data, it is next to impossible to show a solution that you can get working with your own data set.这种问题的问题在于,如果没有看到您的数据,几乎不可能展示您可以使用自己的数据集的解决方案。 It's certainly possible to create a visualization like this with 160 bars, as I can show with some dummy data:用 160 条柱创建这样的可视化当然是可能的,因为我可以用一些虚拟数据来展示:

set.seed(1)

df <- data.frame(x = as.factor(1:160), y = sort(runif(160))/2 + 0.5,
                 group = as.factor(sample(5, 160, TRUE)))

library(ggplot2)

ggplot(df, aes(x, y, fill = group)) + 
  geom_col(width = 0.5) + 
  geom_hline(yintercept = 0.25, color = "#0b192d", size = 0.1) +
  geom_hline(yintercept = 0.5, color = "#0b192d", size = 0.1) +
  geom_hline(yintercept = 0.75, color = "#0b192d", size = 0.1) +
  scale_y_continuous(limits = c(-0.5, 1)) +
  geom_text(label = "Average\nWorking Week\n(Hours)",
            x = 0, y = 0, color = "white", vjust = 1.7, size = 5,
            check_overlap = TRUE, fontface = "bold") +
  coord_polar() +
  theme_dark() +
  scale_fill_manual(values = c("#6a4199", "#ea5f3c", "#f69a40", 
                               "#2dbed3", "#ef0000")) +
  theme(panel.background = element_rect(fill = "#0b192d"),
        axis.text.x = element_text(colour = "white", size = 4),
        panel.grid = element_blank(),
        legend.position = "none",
        plot.background = element_rect(fill = "#0b192d"),
        axis.title = element_blank(),
        axis.text.y = element_blank())

在此处输入图片说明

One of the problems as you can see is that to fit 160 bars around this kind of plot, the text labels have to be tiny, and therefore unreadable unless you are going to print this on a very large (A2 or larger) poster.如您所见,问题之一是要在此类图周围放置 160 个条形,文本标签必须很小,因此无法读取,除非您要将其打印在非常大(A2 或更大)的海报上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM