用ggplot或base R中的圆带和标签绘图?

时间:2016-05-18 02:21:11

标签: r plot ggplot2

我想制作一个类似于下图的情节。我想知道是否可以使用标准库如基本R或ggplot2来实现这一目标?

enter image description here

1 个答案:

答案 0 :(得分:1)

是的,它可以完成,尽管Mike Wise可能是正确的,使用标签/文本部分可能更容易使用网格。这里有一些东西可以帮助你了解情节本身:

首先是一个圆圈函数,我从here

获取
circleFun <- function(center = c(0,0),diameter = 1, npoints = 100){
  r = diameter / 2
  tt <- seq(0,2*pi,length.out = npoints)
  xx <- center[1] + r * cos(tt)
  yy <- center[2] + r * sin(tt)
  return(data.frame(x = xx, y = yy))
}

# and make a circles
circle1 <- circleFun(c(10,10),20,npoints = 100)
circle2 <- circleFun(c(10,10),15,npoints = 100)
circle3 <- circleFun(c(10,10),10,npoints = 100)

# then make some toy data for the points
df <- data.frame(strategy=5:10, offering=c(5,7,9,8,6,9),labelz=c("SAS","ORACLE","IBM","SAP","X-Systems","ABCD"))

maxi <- max(df$offering)/30

#and now some plotting
library(ggplot2)
library(digest) # I needed to call this seperately, should not be necessary

ggplot(data=df, aes(x=strategy, y=offering)) + 
  geom_polygon(data=circle1, aes(x,y), fill = "#99CCFF") +
  geom_polygon(data=circle2, aes(x,y), fill = "#6699CC") +
  geom_polygon(data=circle3, aes(x,y), fill = "#336699") +
  geom_point(aes(size=offering*strategy),color = "white") +
  geom_point(aes(size=1)) +
  geom_text(aes(label=labelz), nudge_y = maxi) +
  coord_cartesian(xlim=c(0,10),ylim=c(0,10)) +
  theme_bw()

这会给你这个情节: enter image description here