[R] ggplot2 and geom_tile

Øystein Godøy o.godoy at met.no
Tue Apr 8 21:55:24 CEST 2014


Dear community,

Please find two sample plots illustrating the problem attached (one 
problematic and one succesful). The commands used to create these are along 
with head of each dataset is provided below:

1. 
ggplot()+geom_tile(data=uvi1$data,aes(x=lon,y=lat,fill=uvic))+scale_x_continuous()+scale_y_continuous()+geom_path(data=norway,aes(x=lon,y=lat,group=group))+coord_equal()
> head(uvi1$data)
    lat   lon uvic uvipoc uvioc uvifcc       ozone snow cloud albedo altitude   
soz         x         y
1 62.50 10.75 2.94   2.50  0.76   1.82 0.007646222  100     6   0.70     0.90 
55.33  542.6142 -2858.031
2 64.75 21.00 2.14   1.82  0.56   0.97 0.008883495  100     7   0.70     0.07 
57.58  954.2729 -2485.966
3 68.00 17.25 2.06   1.75  0.54   0.54 0.007629234  100     8   0.70     0.86 
60.83  685.2720 -2206.937
4 60.00 26.50 3.11   2.65  0.81   0.81 0.008151490  100     8   0.70     0.00 
52.83 1421.3631 -2850.813
5 57.00 12.75 3.57   3.03  0.93   3.57 0.006526370    0     0   0.05     0.04 
49.83  777.1901 -3434.686
6 67.75 15.75 1.99   1.69  0.52   1.93 0.007863361  100     2   0.70     0.25 
60.58  634.5757 -2250.036

2. 
ggplot(data=dailyssi,aes(x=x,y=y,fill=DAILY_SSI))+geom_tile()+geom_path(data=northatlantic,aes(x=x,y=y,group=group,fill=NULL))+coord_equal(xlim=range(tmp2$x),ylim=range(tmp2$y))+scale_fill_gradientn(colours=mycolours(500),breaks=seq(0,max(dailyssi$DAILY_SSI,na.rm=T),50),guide=guide_colorbar(barheight=20))+xlab("Eastings")+ylab("Northings")+ggtitle("Daily 
SSI 2014-04-03 
[W/m²]")+geom_path(data=tmp$latg,aes(x=x,y=y,fill=NULL))+geom_path(data=tmp$long,aes(x=x,y=y,fill=NULL))
> head(dailyssi)
       lat       lon       x   y DAILY_SSI
1 54.57014 -90.03772 -3797.5 2.5  67.63009
2 54.61388 -90.03777 -3792.5 2.5  72.29466
3 54.65763 -90.03782 -3787.5 2.5  61.72242
4 54.70139 -90.03787 -3782.5 2.5  56.26741
5 54.74516 -90.03792 -3777.5 2.5  48.78071
6 54.78894 -90.03797 -3772.5 2.5  46.15528

If I plot the first sample in map projected version only land contours are 
shown.

All the best
Øystein

On Tuesday April 8 2014 20.39.54 Øystein Godøy wrote:
> Dear community,
> 
> I have been using ggplot2 for visualisation and I am really impressed by
> this. I do however have a problem that returns when plotting various types
> of spatial datasets as raster images. This is probably due to me not fully
> understanding the package.
> 
> When I am plotting images using geom_tile, I sometimes only have small dots
> in the image and at other times I have apparently blank images. On other
> occasions it works nicely without me being able to spot the differences
> between these plot requests nor the underlying data. I am usually plotting
> geophysical information either on a geographical grid (latitude/longitude)
> or on a map projection (normally using proj4 for the projection of data).
> 
> I have tried to play with the position attribute, but without success so
> far, but believe that I suffer from some form of effect from this. I have
> tried to google for information and I have read the manual pages but so far
> without success. Do you have some suggested reading for problems like this?
> Is the problem likely to be related to position?
> 
> I apologise for the vague description of the problem.
> 
> All the best
> Øystein
-- 
Dr. Oystein Godoy
Norwegian Meteorological Institute 
P.O.BOX 43, Blindern, N-0313 OSLO, Norway
Ph: (+47) 2296 3000 (switchb) 2296 3334 (direct line)
Fax:(+47) 2296 3050 Institute home page: http://met.no/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: geom_tile_1.png
Type: image/png
Size: 9632 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20140408/bd5ab3ad/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: geom_tile_2.png
Type: image/png
Size: 203419 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20140408/bd5ab3ad/attachment-0005.png>


More information about the R-help mailing list