Commit 5f43ebd9 authored by Franssen, Wietse's avatar Franssen, Wietse
Browse files

added lat/lon addition to ggplotje

parent dc8c3ed1
......@@ -90,14 +90,7 @@ r2ggplotDataStructure <-function(data) {
#' @author Wietse Franssen \email{wietse.franssen@@wur.nl}
#' @keywords internal
#' @export
ggplotje <-function(rdata) {
# theme_update(panel.background = element_rect(fill = "white", colour = NA)
# # ,panel.grid.major = element_line(colour = "grey90", size = 0.2)
# # ,panel.grid.minor = element_line(colour = "grey98", size = 0.5)
# ,panel.grid.major = element_line(colour = "white", size = 0.2)
# ,panel.grid.minor = element_line(colour = "white", size = 0.5)
# ,strip.background = element_rect(fill = "gray80", colour = "gray80")
# )
ggplotje <-function(rdata,lon = NULL, lat = NULL) {
if (!is.na(rdata$Dates$start[1])) {
title=paste0(rdata$Variable$longName, " [",rdata$Variable$units,"]\n(" ,rdata$Dates$start[1], ")")
} else {
......@@ -105,50 +98,30 @@ ggplotje <-function(rdata) {
}
data<-r2ggplotDataStructure(rdata)
# #data<-rdata
# #P <-autoplot(mapBackGround,type = "fixed") +
# p <- ggplot(data = data, aes(x = lon, y = lat)) +
# #xlim(data$lon[1], data$lon[length(data$lon)]) +
# ggtitle(paste0("global discharge","subTitle")) + # plot title
#
# # ylim(data$lat[1], data$lat[length(data$lat)]) +
# theme_bw() +
# # scale_alpha(range=c(0,1), limits=c(0.5,1)) +
# scale_fill_gradient("MAP (mm/yr)", limits=c(260,290)) +
# theme(axis.title.x = element_text(size=16),
# axis.title.y = element_text(size=16, angle=90),
# axis.text.x = element_text(size=14),
# axis.text.y = element_text(size=14),
# panel.grid.major = element_blank(),
# panel.grid.minor = element_blank(),
# legend.position = "right",
# legend.key = element_blank())+
# coord_equal() +
# # labs(x=NULL, y=NULL) +
# xlab(expression(Longitude * ' ' * degree * E * ' ')) +
# ylab(expression(Latitude * ' ' * degree * S * ' ')) +
# #geom_vline(xintercept=seq(7.08, 7.14, by=0.01),ShowGridLines="FALSE") +
# #geom_hline(yintercept=seq(50.93, 50.96, by=0.01),"GridLinesInFront" -> True) +
myPalette <- colorRampPalette(rev(brewer.pal(11, "Spectral")), space="Lab")
zp1 <- ggplot(data,
aes(x = lon, y = lat, fill = data))
zp1 <- zp1 + ggtitle(title) # plot title
zp1 <- zp1 + geom_tile(aes(x = lon, y = lat, fill = data))
zp1 <- zp1 + scale_fill_gradientn(colours = myPalette(100))
#zp1 <- zp1 + scale_x_discrete(expand = c(0, 0))
#zp1 <- zp1 + scale_x_discrete(limits=c(ggdata$lon[1], ggdata$lon[length(ggdata$lon)]))
#zp1 <- zp1 + scale_y_discrete(limits=c(ggdata$lat[1], ggdata$lat[length(ggdata$lat)]))
#zp1 <- zp1 + coord_cartesian(xlim = c(-20, 40),ylim = c(ggdata$lat[1], ggdata$lat[length(ggdata$lat)]))
#zp1 <- zp1 + ylim(ggdata$lat[1], ggdata$lat[length(ggdata$lat)])
zp1 <- zp1 + coord_equal()
zp1 <- zp1 + theme_bw()
zp1 <- zp1 + xlab(expression(Longitude * ' ' * degree * E * ' '))
zp1 <- zp1 + ylab(expression(Latitude * ' ' * degree * S * ' '))
zp1 <- zp1 + theme(legend.title=element_blank())
print(zp1)
myPalette <- colorRampPalette(rev(brewer.pal(11, "Spectral")), space="Lab")
zp1 <- ggplot(data,
aes(x = lon, y = lat, fill = data)) +
ggtitle(title) + # plot title
geom_tile(aes(x = lon, y = lat, fill = data)) +
scale_fill_gradientn(colours = myPalette(100)) +
#zp1 <- zp1 + scale_x_discrete(expand = c(0, 0))
#zp1 <- zp1 + scale_x_discrete(limits=c(ggdata$lon[1], ggdata$lon[length(ggdata$lon)]))
#zp1 <- zp1 + scale_y_discrete(limits=c(ggdata$lat[1], ggdata$lat[length(ggdata$lat)]))
#zp1 <- zp1 + coord_cartesian(xlim = c(-20, 40),ylim = c(ggdata$lat[1], ggdata$lat[length(ggdata$lat)]))
#zp1 <- zp1 + ylim(ggdata$lat[1], ggdata$lat[length(ggdata$lat)])
coord_equal() +
theme_bw() +
xlab(expression(Longitude * ' ' * degree * E * ' ')) +
ylab(expression(Latitude * ' ' * degree * S * ' ')) +
theme(legend.title=element_blank())
if (!is.null(lon) && !is.null(lat)) {
zp1 <- zp1 + scale_shape_identity() + geom_point( colour="black", size = 10, aes_string(x = lon, y = lat, shape=3))
zp1 <- zp1 + geom_point( fill="red",colour="black", size = 6, aes_string(x = lon, y = lat, shape=18))
}
print(zp1)
}
countryMap <- function(lon,lat){
......
......@@ -4,7 +4,7 @@
\alias{ggplotje}
\title{Plot a simple map}
\usage{
ggplotje(rdata)
ggplotje(rdata, lon = NULL, lat = NULL)
}
\arguments{
\item{file}{Name of the NetCDF file}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment