我一直在玩 ggplot2 一堆,发现在 r 中的 ggplot 的绘图区域内添加表
我想知道是否有任何方法可以使用非笛卡尔坐标进行绘图,例如,如果地图坐标用于定位表格。我有一些地图,并认为如果他们可以将相应的数据放在表格中以显示更多细节,那将是很酷的。
如果有人知道非笛卡尔坐标的 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