【发布时间】:2026-02-02 08:10:01
【问题描述】:
我玩了一堆ggplot2,发现Adding table within the plotting region of a ggplot in r
我想知道是否有任何方法可以使用非笛卡尔坐标进行绘图,例如,如果地图坐标用于定位表格。我有一些地图,并认为如果他们可以将相应的数据放在表格中以显示更多细节,那就太棒了。
如果有人知道非笛卡尔坐标的 annotation_custom 解决方法,将不胜感激。
编辑:这是我的地图的图像,我只是在想是否有另一种方法可以在此左侧绘制表格。
编辑:这是我试图做的
编辑:这是情节的基本代码结构
library(ggplot2)
library(ggmap)
plotdata <- read.csv("WellSummary_All_SE_NRM.csv", header = T)
plotdata <- na.omit(plotdata)
plotdata <- plotdata[1:20, c("Unit_No","neg_decimal_lat", "decimal_long", "max_drill_depth", "max_drill_date")]
map.plot<- get_map(location = c(min(plotdata$decimal_long),
min(plotdata$neg_decimal_lat),
max(plotdata$decimal_long),
max(plotdata$neg_decimal_lat)),
maptype ="hybrid",source = "google", zoom=8)
theme_set(theme_bw(base_size = 8))
colormap <- c("darkblue","blue","lightblue", "green", "yellow", "orange","darkorange", "red", "darkred")
myBreaks <- c(0,2, 10, 50, 250, 1250, 2000, 2500)
static.map <- ggmap(map.plot) %+% plotdata +
aes(x = decimal_long,
y = neg_decimal_lat,
z= max_drill_depth)+
stat_summary2d(fun = median, binwidth = c(.03, .03),alpha = 0.7) +
scale_fill_gradientn(name = "depth", colours= colormap, breaks=myBreaks,labels = format(myBreaks),
limits= c(0,2600), space = "Lab") +
labs(x = "Longitude",y = "Latitude")+
geom_text(aes(label=Unit_No),hjust=0, vjust=0,size=2,
position = position_dodge(width=0.9), angle = 45)+
coord_map()
#Creates image of the plot in file to Working Directory
filename=paste("2dmap",".png", sep="")
cat("\t",filename,"file created, saving...\n")
print(static.map)
cat("\tpassed mapping, file now being made\n")
ggsave(filename=filename,
plot = static.map,
scale = 1,
width = 6, height = 4,
dpi = 300)
我今天会尝试上传数据,已经为一些指针喝彩了!
我已经上传了数据,不用担心渐变值和文本标签的位置,因为我可以稍后修复它们我还将链接当前的 ggmap 代码,但我使用了一个非常大的循环来对数据进行排序。
https://drive.google.com/file/d/0B8qOIJ-nPp9rM1U1dkEzMUM0Znc/edit?usp=sharing
【问题讨论】:
-
您能否提供一个地图示例和您要嵌入的数据?将文件上传到某处(例如 Dropbox)并发布链接。
-
这个answer of me about plotting barplots on a map 可能会对您有所帮助。另请查看how to give reproducible answers上的描述。
-
您真的需要特定坐标的表格吗?否则,您可以简单地 grid.draw() 绘图顶部的表格并使用“标准化父坐标”将其放置在设备窗口的任何位置。
-
查看 ggsubplot 包,也许它可以做你想做的事?
-
我看过 ggsuplot 包,但找不到如何绘制表格,我看到的唯一表格是针对特定点的线形数据,不显示完整的数据,例如我正在努力。