r - 在 R 中使用质心的条形图
问题描述
我想使用质心位置创建几个条形图来定位它们。我已经有一个要与之结合的多边形的绘图代码。这些来自平面图,而不是世界各地的地理区域。不幸的是,我有几点与下面链接中的示例不同,后者只有三点。如何使用 ggplot2 绘制此图以涵盖我的所有观点?这是我想将条形图添加到的示例 ggplot 代码:
ggplot() + theme_minimal()+ theme(plot.title = element_text(hjust = 0.5,face="bold",size=14),line=element_line(size=0.2),
panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
axis.text.x=element_blank(),axis.text.y=element_blank(),strip.text = element_text(size=11, face = "bold"),axis.title.x = element_blank(),
axis.title.y = element_blank(),legend.title=element_text(size=9, face = "bold"))+
geom_polygon(aes(x =long, y = lat, group = group), size=0.5,color="black",fill="black",alpha=0.2, data =shp1_data.frame)+
geom_polygon(aes(x =long, y = lat, group = group), size=0.5,color="white",fill="black",alpha=0.2, data =shp4_data.frame)
head(read.table("Sampledata.txt",header=T),15)
Location_i variable value x y
1 A005 Head 0.0000000 1238.509 -970.4791
2 A005 Hair 0.0000000 1238.509 -970.4791
3 A005 Knees 0.1666667 1238.509 -970.4791
4 A005 Ears 0.0000000 1238.509 -970.4791
5 A005 Heart 0.0000000 1238.509 -970.4791
6 A005 Mouth -0.1666667 1238.509 -970.4791
7 A005 Toes 0.0000000 1238.509 -970.4791
8 A028 Head 0.0000000 1538.509 -870.4791
9 A028 Hair 0.0000000 1538.509 -870.4791
10 A028 Knees 0.0000000 1538.509 -870.4791
11 A028 Ears 0.0000000 1538.509 -870.4791
12 A028 Heart 1.0000000 1538.509 -870.4791
13 A028 Mouth -1.0000000 1538.509 -870.4791
14 A028 Toes 0.0000000 1538.509 -870.4791
15 A030 Toes 0.0000000 1738.509 -870.6731
我已经在我的驱动器中放了一个数据样本,其中包含 x 和 y 位置字段、值、可变广告位置 ID。该图使用变量字段围绕每个质心 (location_i) 分组。
##To read in the text file after downloading
A1<-read.table("Sampledata.txt",header=T)
解决方案
推荐阅读
- python-3.x - 这个基本 Python 类中的值是如何确定的?
- java - 无法创建 tempDir。java.io.tmpdir 设置为 C:\windows\
- c# - XML whit 多节点到 C# 中的数据表
- flutter - 在颤振中, RaisedButton 在其构造函数中有 disabledColor 选项,但没有禁用它的选项?
- bash - 如何使用多个 shebang 解释器运行同一个文件?
- ajax - 如何在 cakephp 2 控制器中获取 ajax 请求数据?
- c# - 应用启动后,Windows 10 IoT Core 终止与 Xbox 360 无线游戏控制器的连接
- vue.js - 如何在范围外更改 vue.js 组件数据
- bash - 每个输入文件创建单独的输出文件
- python - Pandas 读取 (Excel) 文本列,并返回相似率