Re-create 图形设计
Re-create graph design
[更新]:我发现了一个很棒的条形图图形设计,我想在 R 中重新创建它,但我在处理一些主要元素时遇到困难(来自 538)。下面是图表的图片和我目前的进度。
这是我要重新创建的图表
这是我的代码:
convicted <- c(0.68, 0.33)
incarcertated <- c(0.48, 0.12)
group <- c("GENERAL POPULATION", "LAW ENFORCEMENT")
df <- data.frame(convicted, incarcertated, group)
mdf <- melt(df)
ggplot(mdf) +
geom_bar(aes(x=variable, y=1), stat="identity", alpha=.1, position=position_dodge(1)) +
geom_bar(aes(x=variable, y=value, fill=group), stat="identity", position=position_dodge(1)) +
scale_fill_manual(values=c("#058cd3", "#ff2700"))
我不确定该怎么做
- 让 "group" 标签位于每个组的顶部并分开
他们 *(关键设计元素)
- 创建标题和灰色副标题
- 获取颜色灰色条与彩色条分隔相同的距离
酒吧
- 获取要用条形图闪避的值标签
我要补充一点,在我理想的游戏中,颜色将被分开(因此两组中的颜色相同)。
希望尽可能准确地帮助 re-creating 此聊天。我很确定这是在 R 中创建的,所以我知道它可以完成。感谢您的帮助!
[更新]:感谢hfty的帮助,我已经很接近了,但是我得到了一个奇怪的边框效果,我无法上传到评论区,所以我在这里做了。这是怎么回事?
这很可能不是单独使用 R 创建的。如果是,它可能随后在 Illustrator 或类似软件中进行了编辑。但是,这里有一些 ggplot2 可以让您接近所需结果的方法:
- Get the "group" label to sit on top of each group and separate them *(key design element)
使用 facet_wrap()
的组合来分隔图和 coord_flip()
来翻转它应该可以让你到达那里。
ggplot(mdf, aes(x=variable, y=value, fill=group)) +
facet_wrap(~group, ncol=1) +
geom_bar(stat="identity", position=position_dodge(1)) +
coord_flip() + ...
- Create a title and gray subheader
用 ggplot 做这个没有简单的方法。我建议稍后编辑它,例如与插画家。但是,您可以添加一个粗体标题,例如像这样:
... + ggtitle(expression(atop(bold("What Percentage of Crimininal Defendants Are\nConvicted and Incarcerated?")))) + ...
- get the color gray bars to separate the same distance as the colored bars
你快到了:
... + geom_bar(aes(x=variable, y=1), stat="identity", alpha=.1,
position=position_dodge(1), fill = "#aaaaaa") + ...
- get the value labels to dodge with bar charts
将其与其他一些调整放在一起,例如使用 ggthemr 清理默认样式:
# devtools::install_github('ggthemr', 'cttobin') # Install ggthemr
library(ggthemr)
ggthemr('fresh')
ggplot(mdf, aes(x=variable, y=value, fill=group)) + facet_wrap(~group, ncol=1) +
geom_bar(stat="identity", position=position_dodge(1)) +
geom_bar(aes(x=variable, y=1), stat="identity", alpha=.1, position=position_dodge(1), fill = "#aaaaaa") +
geom_text(aes(label=round(100*value)), hjust=-0.5) +
scale_fill_manual(values=c("#058cd3", "#ff2700")) +
theme(strip.text.x = element_text(hjust=-0.15),
axis.text.x = element_blank(),
axis.line = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
legend.title = element_blank(),
axis.title.y=element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "none"
) +
coord_flip() +
ggtitle(expression(atop(bold("What Percentage of Crimininal Defendants Are\nConvicted and Incarcerated?")))) +
theme(plot.title = element_text(size = 20, hjust=-0.4, vjust=0.2))
[更新]:我发现了一个很棒的条形图图形设计,我想在 R 中重新创建它,但我在处理一些主要元素时遇到困难(来自 538)。下面是图表的图片和我目前的进度。
这是我要重新创建的图表
这是我的代码:
convicted <- c(0.68, 0.33)
incarcertated <- c(0.48, 0.12)
group <- c("GENERAL POPULATION", "LAW ENFORCEMENT")
df <- data.frame(convicted, incarcertated, group)
mdf <- melt(df)
ggplot(mdf) +
geom_bar(aes(x=variable, y=1), stat="identity", alpha=.1, position=position_dodge(1)) +
geom_bar(aes(x=variable, y=value, fill=group), stat="identity", position=position_dodge(1)) +
scale_fill_manual(values=c("#058cd3", "#ff2700"))
我不确定该怎么做
- 让 "group" 标签位于每个组的顶部并分开 他们 *(关键设计元素)
- 创建标题和灰色副标题
- 获取颜色灰色条与彩色条分隔相同的距离 酒吧
- 获取要用条形图闪避的值标签
我要补充一点,在我理想的游戏中,颜色将被分开(因此两组中的颜色相同)。
希望尽可能准确地帮助 re-creating 此聊天。我很确定这是在 R 中创建的,所以我知道它可以完成。感谢您的帮助!
[更新]:感谢hfty的帮助,我已经很接近了,但是我得到了一个奇怪的边框效果,我无法上传到评论区,所以我在这里做了。这是怎么回事?
这很可能不是单独使用 R 创建的。如果是,它可能随后在 Illustrator 或类似软件中进行了编辑。但是,这里有一些 ggplot2 可以让您接近所需结果的方法:
- Get the "group" label to sit on top of each group and separate them *(key design element)
使用 facet_wrap()
的组合来分隔图和 coord_flip()
来翻转它应该可以让你到达那里。
ggplot(mdf, aes(x=variable, y=value, fill=group)) +
facet_wrap(~group, ncol=1) +
geom_bar(stat="identity", position=position_dodge(1)) +
coord_flip() + ...
- Create a title and gray subheader
用 ggplot 做这个没有简单的方法。我建议稍后编辑它,例如与插画家。但是,您可以添加一个粗体标题,例如像这样:
... + ggtitle(expression(atop(bold("What Percentage of Crimininal Defendants Are\nConvicted and Incarcerated?")))) + ...
- get the color gray bars to separate the same distance as the colored bars
你快到了:
... + geom_bar(aes(x=variable, y=1), stat="identity", alpha=.1,
position=position_dodge(1), fill = "#aaaaaa") + ...
- get the value labels to dodge with bar charts
将其与其他一些调整放在一起,例如使用 ggthemr 清理默认样式:
# devtools::install_github('ggthemr', 'cttobin') # Install ggthemr
library(ggthemr)
ggthemr('fresh')
ggplot(mdf, aes(x=variable, y=value, fill=group)) + facet_wrap(~group, ncol=1) +
geom_bar(stat="identity", position=position_dodge(1)) +
geom_bar(aes(x=variable, y=1), stat="identity", alpha=.1, position=position_dodge(1), fill = "#aaaaaa") +
geom_text(aes(label=round(100*value)), hjust=-0.5) +
scale_fill_manual(values=c("#058cd3", "#ff2700")) +
theme(strip.text.x = element_text(hjust=-0.15),
axis.text.x = element_blank(),
axis.line = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
legend.title = element_blank(),
axis.title.y=element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "none"
) +
coord_flip() +
ggtitle(expression(atop(bold("What Percentage of Crimininal Defendants Are\nConvicted and Incarcerated?")))) +
theme(plot.title = element_text(size = 20, hjust=-0.4, vjust=0.2))