r - 在不使用极坐标的情况下将极地背景添加到 ggplot
问题描述
我想使用笛卡尔坐标系绘制图,然后将其覆盖在极坐标图背景上,就像coord_polar
. Panel.background
fromtheme.R
只有element_rect
; 理想情况下,我可以使用类似element_polar
.
有什么办法可以做到这一点?
简单地使用coord_polar
是行不通的,因为我还在绘制各种其他几何图形,这些几何图形以特殊方式映射到coord_polar
(例如,geom_ellispis
从ggforce
包中)。
可重现的示例代码:
library(ggplot2)
library(ggforce) # NB this is the github version #install_github("thomasp85/ggforce"). Includes 'geom_ellipsis'
#### Make example data
r<-runif(50,-100,100) # radial coordinates
theta<-runif(50,0,2) # theta
a<-runif(50,1,20)
b<-runif(50,1,20)
# Convert r and theta to cartesian:
x<-r*cos(theta*pi) # x-coordinate of ellipse foci
y<-r*sin(theta*pi) # y-coordinate of ellipse foci
angle.random<-runif(50,min=0,max=2) # random angle for ellipsis rotation
df<-as.data.frame(cbind(r,theta,x,y,a,b,angle.random))
# Make plots
# Plot should look like this:
ggplot(df,aes(x,y))+
geom_point(aes(x,y))+
geom_ellipsis(data=df,aes(x0=x,y0=y,a=a,b=b,angle=angle.random,fill=T))
# But I want the panel background in polar coordinates (and auto-adjusing to scale), like this:
ggplot(df,aes(x,y))+
geom_point(aes(x,y))+
coord_polar()
# However, using geom_ellipsis (among other functions) has idiosyncratic effects in non-cartesian coordinate systems:
ggplot(df,aes(r,theta))+
geom_point(aes(x,y))+
geom_ellipsis(data=df,aes(x0=x,y0=y,a=a,b=b,angle=angle.random,fill=T))+
coord_polar()
我想要第三个情节的极地背景,以及第一个情节的未扭曲椭圆。有没有办法做到这一点?
解决方案
推荐阅读
- azure-devops - 如何与使用 azure devops 创建的利益相关者共享魅力测试报告
- javascript - 如何将数据从服务器传输到客户端 js 文件?
- asp.net-mvc - Select2 Asp.net MVC - 初始数据不重视下拉列表
- angularjs - 如何在 angularjs 中添加引导日期时间选择器
- perl - new SomeModule::SomeName vs SomeModule::SomeName->new(),有什么区别?
- angular - 使用primeng进行角度测试:NullInjectorError: StaticInjectorError(DynamicTestModule)[ButtonDirective -> ElementRef
- java - 找到 Selenium 按钮但未执行单击
- ios - 由于 MDFInternationalization 和 MaterialComponents 目录不存在,无法 tns 构建 ios
- php - TYPO3:如何在 Extbase 扩展中使用外部 PHP 库(不安装 composer)
- ffmpeg - FFMpeg amix 过滤器音量变化。解释请求