Avoid axis labels, ticks and marks in ggRGB() plot

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Avoid axis labels, ticks and marks in ggRGB() plot

Agustin Lobo
In order to save space, I prefer to avoid coordinates in the plot
generated by ggRGB. Is there any way? I've tried:

ggplot() +
ggRGB(rlogo, r=1, g=2, b=3,ggLayer=TRUE) +
  theme(
    axis.text = element_blank(),
    axis.ticks = element_blank(),
    axis.title = element_blank())

but get an empty plot.
I can circumvent the problem as follows, but it is kind of ugly and complicated,
there must be another way:

a <- as(extent(rlogo), 'SpatialPolygons')
y <- fortify(a,region=id)
ggplot(data=y,aes(y=lat, x=long)) +
  ggRGB(rlogo, r=1, g=2, b=3,ggLayer=TRUE) +
  geom_polygon(colour="yellow", fill=NA) +
  guides(fill=FALSE) +
  coord_fixed(ratio=1) +
  theme(
    axis.text = element_blank(),
    axis.ticks = element_blank(),
    axis.title = element_blank())

Agus

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Avoid axis labels, ticks and marks in ggRGB() plot

Benjamin Leutner
The problem with your first approach is that there is no "data layer"
which could span the coordinate axes.
Since ggRGB by default uses an annotation_raster() in order to keep your
"fill" dimension free for other data,  the coordinate limits are empty,
hence the plotted raster is lost in the dimensionless void and you get
see nothing ;-)

I would recommend to start your plot with ggRGB like this:

ggRGB(rlogo, r=1, g=2, b=3) +
   theme(
     axis.text = element_blank(),
     axis.ticks = element_blank(),
     axis.title = element_blank())


If you do want to use it with ggLayer = TRUE, there should be at least
one "geom" with actual data in it (or you'd have to set ggRGB(...,
geom_raster=TRUE), but I don't see any benefit in that and it would give
you a huge legend with one entry per rgb color...)

best,
Benjamin

On 03/13/2017 12:10 PM, Agustin Lobo wrote:

> In order to save space, I prefer to avoid coordinates in the plot
> generated by ggRGB. Is there any way? I've tried:
>
> ggplot() +
> ggRGB(rlogo, r=1, g=2, b=3,ggLayer=TRUE) +
>    theme(
>      axis.text = element_blank(),
>      axis.ticks = element_blank(),
>      axis.title = element_blank())
>
> but get an empty plot.
> I can circumvent the problem as follows, but it is kind of ugly and complicated,
> there must be another way:
>
> a <- as(extent(rlogo), 'SpatialPolygons')
> y <- fortify(a,region=id)
> ggplot(data=y,aes(y=lat, x=long)) +
>    ggRGB(rlogo, r=1, g=2, b=3,ggLayer=TRUE) +
>    geom_polygon(colour="yellow", fill=NA) +
>    guides(fill=FALSE) +
>    coord_fixed(ratio=1) +
>    theme(
>      axis.text = element_blank(),
>      axis.ticks = element_blank(),
>      axis.title = element_blank())
>
> Agus
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

--
Benjamin Leutner M.Sc.
PhD candidate

Department of Remote Sensing
University of Wuerzburg
Campus Hubland Nord 86
97074 Wuerzburg, Germany

Tel: +49-(0)931-31 89594
Fax: +49-(0)931-31 89594-0
Email: [hidden email]
Web: http://www.fernerkundung.uni-wuerzburg.de

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Avoid axis labels, ticks and marks in ggRGB() plot

Agustin Lobo
Yes! Thanks!
I knew there had to be a better way. For my set of plots I can set
t <- theme(
  axis.text = element_blank(),
  axis.ticks = element_blank(),
  axis.title = element_blank())

and then

ggRGB(rlogo, r=1, g=2, b=3) + t +ggtitle("patatin")

Agus



On Mon, Mar 13, 2017 at 2:05 PM, Benjamin Leutner
<[hidden email]> wrote:

> The problem with your first approach is that there is no "data layer" which
> could span the coordinate axes.
> Since ggRGB by default uses an annotation_raster() in order to keep your
> "fill" dimension free for other data,  the coordinate limits are empty,
> hence the plotted raster is lost in the dimensionless void and you get see
> nothing ;-)
>
> I would recommend to start your plot with ggRGB like this:
>
> ggRGB(rlogo, r=1, g=2, b=3) +
>   theme(
>     axis.text = element_blank(),
>     axis.ticks = element_blank(),
>     axis.title = element_blank())
>
>
> If you do want to use it with ggLayer = TRUE, there should be at least one
> "geom" with actual data in it (or you'd have to set ggRGB(...,
> geom_raster=TRUE), but I don't see any benefit in that and it would give you
> a huge legend with one entry per rgb color...)
>
> best,
> Benjamin
>
>
> On 03/13/2017 12:10 PM, Agustin Lobo wrote:
>>
>> In order to save space, I prefer to avoid coordinates in the plot
>> generated by ggRGB. Is there any way? I've tried:
>>
>> ggplot() +
>> ggRGB(rlogo, r=1, g=2, b=3,ggLayer=TRUE) +
>>    theme(
>>      axis.text = element_blank(),
>>      axis.ticks = element_blank(),
>>      axis.title = element_blank())
>>
>> but get an empty plot.
>> I can circumvent the problem as follows, but it is kind of ugly and
>> complicated,
>> there must be another way:
>>
>> a <- as(extent(rlogo), 'SpatialPolygons')
>> y <- fortify(a,region=id)
>> ggplot(data=y,aes(y=lat, x=long)) +
>>    ggRGB(rlogo, r=1, g=2, b=3,ggLayer=TRUE) +
>>    geom_polygon(colour="yellow", fill=NA) +
>>    guides(fill=FALSE) +
>>    coord_fixed(ratio=1) +
>>    theme(
>>      axis.text = element_blank(),
>>      axis.ticks = element_blank(),
>>      axis.title = element_blank())
>>
>> Agus
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> --
> Benjamin Leutner M.Sc.
> PhD candidate
>
> Department of Remote Sensing
> University of Wuerzburg
> Campus Hubland Nord 86
> 97074 Wuerzburg, Germany
>
> Tel: +49-(0)931-31 89594
> Fax: +49-(0)931-31 89594-0
> Email: [hidden email]
> Web: http://www.fernerkundung.uni-wuerzburg.de
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Loading...