Bullet Charts

By Data Tricks, 1 March 2018

Last modified 5 September 2019

rm(list = ls())
library(ggplot2)

data <- data.frame(Year=rep(c("2014","2015","2016","2017"), times=3, each=1),
 Category=rep(c("One","Two","Three"), times=1, each=4),
 Value=c(55,62,70,73,30,39,41,56,15,22,26,30),
 Width=rep(c(0.9,0.7,0.5), times=1, each=4)
)

data$Category <- factor(data$Category, levels = c("One", "Two", "Three"))

gg <- ggplot(data)
gg <- gg + geom_bar(aes(Year, Value, fill=Category), width=data$Width, stat="identity")
gg <- gg + scale_fill_manual("Key", values = c("One" = "#121c23", "Two" = "#3d5f77", "Three" = "#7db4db"))
gg <- gg + xlab("") + ylab("")
gg <- gg + theme(panel.grid.major = element_blank(),
      panel.grid.minor = element_blank(),
      panel.background = element_blank(),
      axis.line.x = element_line(color="#919191", size = 0.1),
      axis.line.y = element_line(color="#919191", size = 0.1))

print(gg)

 

data <- data.frame(Year=rep(c("2014","2015","2016","2017"), times=3, each=1),
 Category=rep(c("One","Two","Three"), times=1, each=4),
 Value=c(55,62,70,73,30,39,41,56,15,22,26,30),
 Width=rep(c(0.3,0.6,0.9), times=1, each=4)
)

data$Category <- factor(data$Category, levels = c("One", "Two", "Three"))

gg <- ggplot(data)
gg <- gg + geom_bar(aes(Year, Value, fill=Category), width=data$Width, stat="identity")
gg <- gg + scale_fill_manual("Key", values = c("One" = "#121c23", "Two" = "#3d5f77", "Three" = "#7db4db"))
gg <- gg + xlab("") + ylab("")
gg <- gg + theme(panel.grid.major = element_blank(),
 panel.grid.minor = element_blank(),
 panel.background = element_blank(),
 axis.line.x = element_line(color="#919191", size = 0.1),
 axis.line.y = element_line(color="#919191", size = 0.1))

print(gg)

 

Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

Please note that your first comment on this site will be moderated, after which you will be able to comment freely.