Can you plot a table onto a ggmap similar to annotation_custom method for non- Cartesian coordinates

StackOverflow https://stackoverflow.com/questions/21447597

  •  04-10-2022
  •  | 
  •  

Pergunta

I have been playing around with ggplot2 a bunch and found Adding table within the plotting region of a ggplot in r

I was wondering is there any method for this for plotting using non cartesian coordinates, eg if map coordinates were used for the positioning of the table. I had some maps and thought it would be cool if they could have their corresponding data in a table for points to show more detail.

If anyone knows a work around for annotation_custom for non cartesian coordinates it would be greatly appreciated.

EDIT:Here is a image of what my map looks like, I was just thinking is there another way to plot the table on the left side of this. enter image description here

EDIT: here is what Im attempting to do enter image description here

EDIT: Here is the basic code structure for the plot

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)

I will try to upload the data today, cheers for some of the pointers already!

I have uploaded the data, dont worry about the positioning of the gradient values and text tags as I can fix them later I will also link the current ggmap code but I am using a very large loop for the data to be sorted.

https://drive.google.com/file/d/0B8qOIJ-nPp9rM1U1dkEzMUM0Znc/edit?usp=sharing

Foi útil?

Solução

try this,

library(gridExtra)
grid.arrange(tableGrob(head(iris)), qplot(1,1), ncol=2)

annotation_custom wouldn't help, it's meant for adding things inside the plot panel, not to the side.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top