3

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

peterh
  • 11,875
  • 18
  • 85
  • 108
Cam.f
  • 105
  • 2
  • 9
  • Can you provide an example of a map and the data you want to embed? Upload the files somewhere (e.g. Dropbox) and post a link. – jlhoward Jan 30 '14 at 05:09
  • Possibly this [answer of me about plotting barplots on a map](http://stackoverflow.com/questions/20465070/barplots-on-a-map/20468836#20468836) might help you. Also look at the description on [how to give reproducible answers](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Jaap Jan 30 '14 at 09:36
  • do you really need the table at specific coordinates? Otherwise you can simply grid.draw() the table on top of the plot and fiddle with "normalised parent coordinates" to position it anywhere on the device window. – baptiste Jan 30 '14 at 11:56
  • Check out the ggsubplot package, maybe that can do what you want? – JeremyS Jan 31 '14 at 01:07
  • I have had a look at the ggsuplot package but cant find how to plot a table , the only tables I have seen have been with line bar data that is for a specific point and doesnt show complete data like I am trying to do. – Cam.f Jan 31 '14 at 01:14

1 Answers1

1

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.

baptiste
  • 75,767
  • 19
  • 198
  • 294