我希望在R中大致复制以下3d直方图(在Excel中制作)。窍门是,标签应位于大法官姓名的之间,因为条形图用于描绘数字有时候,某些法官投票反对其他法官。
您可以使用以下代码生成数据:
cutpoints <- c(0, 22, 16, 12, 13, 7, 16, 13, 20)
justice_names <- c("Peckham", "Brewer", "Shiras",
"Fuller", "Gray", "Brown", "McKenna", "White", "Harlan")
答案 0 :(得分:0)
这是一个粗略的复制品,省略了3D。
将x轴绘制为数字并在之后应用标签,可以将标签向右移动半个标记。
library(ggplot2)
cutpoints <- c(0, 22, 16, 12, 13, 7, 16, 13, 20)
justice_names <- c("Peckham",
"Brewer",
"Shiras",
"Fuller",
"Gray",
"Brown",
"McKenna",
"White",
"Harlan")
hist_data <- data.frame(justice_names, cutpoints, order = seq(1:9))
hist_data$justice_names <-
factor(hist_data$justice_names, levels = hist_data$justice_names)
ggplot(hist_data, aes(x = order, y = cutpoints)) +
geom_bar(stat = "identity", width = 0.5) +
scale_x_continuous(breaks = hist_data$order + 0.5, # Shift labels by 0.5
labels = hist_data$justice_names) +
geom_text(aes(label = cutpoints), vjust = 0, nudge_y = 0.25) +
labs(x = "Justice", y = "Number",
title = "Fig A-1. Number of Cutpoints, 1899-1901") +
theme(panel.grid.minor = element_blank(),
panel.grid.major.x = element_line(linetype = "dashed"))