Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何仅显示带有刻面的极坐标图的部分绘图区域?_R_Ggplot2 - Fatal编程技术网

R 如何仅显示带有刻面的极坐标图的部分绘图区域?

R 如何仅显示带有刻面的极坐标图的部分绘图区域?,r,ggplot2,R,Ggplot2,假设极坐标中有一个数据集要绘制为扇区 library(ggplot2) library(reshape2) data <- melt(matrix(rnorm(1000), nrow = 20)) data$type <- 1:2 data$Var1 <- data$Var1*6 - 60 ggplot(data, aes(Var1, Var2)) + geom_tile(aes(fill = value)) + coord_polar(theta = "x",

假设极坐标中有一个数据集要绘制为扇区

library(ggplot2)
library(reshape2)
data <- melt(matrix(rnorm(1000), nrow = 20))
data$type <- 1:2
data$Var1 <- data$Var1*6 - 60

ggplot(data, aes(Var1, Var2)) + 
  geom_tile(aes(fill = value)) + 
  coord_polar(theta = "x", start = pi) + 
  scale_x_continuous(limits = c(-180, 180)) +
  facet_wrap(~type)
库(ggplot2)
图书馆(E2)

数据这是一种不雅观的黑客行为,但您可以使用
grid
函数来掩盖您不想要的区域。例如:

library(ggplot2)
library(reshape2)
library(grid)

data <- melt(matrix(rnorm(1000), nrow = 20))
data$type <- 1:2
data$Var1 <- data$Var1*6 - 60

p1 = ggplot(data, aes(Var1, Var2)) + 
  geom_tile(aes(fill = value)) + 
  coord_polar(theta = "x", start = pi) + 
  scale_x_continuous(limits = c(-180, 180)) +
  facet_wrap(~type)
g1 = ggplotGrob(p1)

grid.newpage()
pushViewport(viewport(height=1, width=1, clip="on"))
grid.draw(g1)
grid.rect(x=0,y=0,height=1, width=2, gp=gpar(col="white"))
库(ggplot2)
图书馆(E2)
图书馆(网格)

我怀疑ggplot2是否有办法做到这一点。我认为,如果你把它变成一个grob,并在网格级别进行黑客攻击,这可能会是一项相当大的工作。我会寻找一种不同的方法。我同意@Roland。我想到了两个选项:1)你能使用
coord\u cartesian
处理你的数据吗?如果不是,并且如果要使用
ggplot2
,则使用图像处理程序裁剪绘图可能是最简单的解决方案。当然,在R中也可以这样做,但正如罗兰所说,这需要一些修改。我没有尝试过,但是把图例向上移动,然后将较低的绘图边距限制为负值怎么样?