Skip to content

Instantly share code, notes, and snippets.

@malinxiao
Last active December 20, 2017 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malinxiao/7826e0c8be9023c12d47b56070dbe5cd to your computer and use it in GitHub Desktop.
Save malinxiao/7826e0c8be9023c12d47b56070dbe5cd to your computer and use it in GitHub Desktop.
library(ggplot2)
library(grid)
p <- ggplot(dataset, aes(VisionScore, ExcutionScore))
p <- p + scale_x_continuous(expand = c(0, 0), limits = c(0, 100))
p <- p + scale_y_continuous(expand = c(0, 0), limits = c(0, 100))
p <- p + labs(x="COMPLETEMENT OF VISION",y="ABILITY TO EXCUTE")
p <- p + theme(axis.title.x = element_text(hjust = 0, vjust=4, colour="darkgrey",size=10,face="bold"))
p <- p + theme(axis.title.y = element_text(hjust = 0, vjust=0, colour="darkgrey",size=10,face="bold"))
p <- p + theme(
axis.ticks.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.y=element_blank(),
axis.text.y=element_blank()
)
p <- p+ggtitle("Gartner Magic Quadrant - Created for Power BI using ggpolt2")
p <- p +
annotate("rect", xmin = 50, xmax = 100, ymin = 50, ymax = 100, fill= "#F8F9F9") +
annotate("rect", xmin = 0, xmax = 50, ymin = 0, ymax = 50 , fill= "#F8F9F9") +
annotate("rect", xmin = 50, xmax = 100, ymin = 0, ymax = 50, fill= "white") +
annotate("rect", xmin = 0, xmax = 50, ymin = 50, ymax = 100, fill= "white")
p <- p + theme(panel.border = element_rect(colour = "lightgrey", fill=NA, size=4))
p <- p + geom_hline(yintercept=50, color = "lightgrey", size=1.5)
p <- p + geom_vline(xintercept=50, color = "lightgrey", size=1.5)
p <- p + geom_label(aes(x = 25, y = 97, label = "CALLENGERS"),
label.padding = unit(2, "mm"), fill = "lightgrey", color="white")
p <- p + geom_label(aes(x = 75, y = 97, label = "LEADERS"),
label.padding = unit(2, "mm"), fill = "lightgrey", color="white")
p <- p + geom_label(aes(x = 25, y = 3, label = "NICHE PLAYERS"),
label.padding = unit(2, "mm"), fill = "lightgrey", color="white")
p <- p + geom_label(aes(x = 75, y = 3, label = "VISIONARIES"),
label.padding = unit(2, "mm"), fill = "lightgrey", color="white")
p <- p + geom_point(colour = "#2896BA", size = 5)
p <- p + geom_text(aes(label=Company),colour="#2896BA", hjust=-0.3, vjust=0.25, size=3.2)
p <- p + annotation_custom(
grob = linesGrob(arrow=arrow(type="open", ends="last", length=unit(2,"mm")),
gp=gpar(col="lightgrey", lwd=4)),
xmin = -2, xmax = -2, ymin = 25, ymax = 40
)
p <- p + annotation_custom(
grob = linesGrob(arrow=arrow(type="open", ends="last", length=unit(2,"mm")),
gp=gpar(col="lightgrey", lwd=4)),
xmin = 28, xmax = 43, ymin = -3, ymax = -3
)
gt = ggplot_gtable(ggplot_build(p))
gt$layout$clip[gt$layout$name=="panel"] = "off"
grid.draw(gt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment