创建类似极坐标图样式的局部圆弧图?

Create a partial arc graph in style similar to polar graph?

我想在 R 中创建一个 polar/radar 样式的图表,它只显示部分弧而不是完整的圆。

我查看了 Plotrix 和 Pracma 包,但我只能创建一个完整的圆极坐标图,就像我在这里展示的那样(创建的是 Pracma)

我想做的是在极弧图表的 0 到 270 度范围内创建一个 1/4 圆弧,然后绘制从中心向外边缘辐射的数据点以指示相对受欢迎程度.当它接近外环时,数据将表明 popularity/adoption 速率越来越低。

我们在基础图形中从头开始创建极坐标图布局:

## Fake data
set.seed(493)
dat = data.frame(theta=runif(20, 3*pi/2, 2*pi), r=sample(1:10, 20, replace=TRUE))

# Calculate x and y values from r and theta
dat$x = dat$r * cos(dat$theta)
dat$y = dat$r * sin(dat$theta)

## 1:1 aspect ratio for plot
par(pty="s")

## Create plot layout
plot(NA,NA, 
     xlim=c(0, ceiling(max(c(dat$x,dat$y)))), 
     ylim=c(-ceiling(max(c(dat$x,dat$y))),0),
     frame.plot=FALSE,
     xaxt="n", yaxt="n", xlab="", ylab="")

## Add axes
axis(3, pos=0, at=seq(0,10,1))
axis(2, pos=0, at=seq(-10,0,1), las=1, labels=c(10:0))

## Add grid lines
angle = seq(0, -pi/2, length.out=100)
invisible(lapply(1:10, function(r) {
  lines(r*cos(angle), r*sin(angle), lwd=0.5, col="grey40", lty="12")
}))

## Add data
invisible(lapply(1:nrow(dat), function(i) {
  lines(c(0,dat$x[i]), c(0,dat$y[i]), col="blue")
}))

原答案

使用 ggplot2:

library(ggplot2)

set.seed(493)
dat = data.frame(x=runif(20, 3*pi/2, 2*pi), value=sample(1:10, 20, replace=TRUE))

ggplot(dat, aes(x=x, xend=x, y=0, yend=value)) + 
  geom_segment(x=3*pi/2, xend=2*pi, y=0, yend=0 ,color="red") +
  geom_segment(color="blue") +
  scale_y_continuous(limits=c(-2,10), breaks=seq(0,10,2)) +
  scale_x_continuous(limits=c(0,2*pi), breaks=seq(0, 2*pi, length.out=13)[-13], 
                     labels=seq(0,360,length.out=13)[-13]) +
  coord_polar(start=-pi/2, direction=-1)