0

I am looking to reproduce roughly the following 3d histogram (made in Excel) in R. The trick is that the labels should fall between the Justice names, as the bars are meant to delineate the number of times certain justices voted against other justices. enter image description here

You can use the following code to generate the data:

cutpoints <- c(0, 22, 16, 12, 13, 7, 16, 13, 20)

justice_names <- c("Peckham", "Brewer", "Shiras", 
    "Fuller", "Gray", "Brown", "McKenna", "White", "Harlan")  
aosmith
  • 34,856
  • 9
  • 84
  • 118
St4096
  • 75
  • 6
  • You can't draw 3d plots in ggplot2. I assume this was an intentional decision by the developers, because they generally don't include problematic plot types in ggplot, and 3d plots like this one [distort data by not using proportional ink](https://callingbullshit.org/tools/tools_proportional_ink.html) – Jan Boyer Aug 22 '18 at 16:26
  • I've answered a question on simulating [Excel graphics with ggplot2](https://stackoverflow.com/questions/45862606/excel-graphics-with-ggplot2/) before. Not my proudest moment, but it can be done. I strongly recommend simply shifting the labels as per pwrignall's answer below, though. – Z.Lin Aug 30 '18 at 06:05

1 Answers1

0

Here's a rough reproduction, omitting the 3D.

Plotting the x-axis as numeric and applying labels after allows you to shift the labels to the right by half a mark.

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"))
pwrignall
  • 26
  • 4