[R-sig-Geo] plotRGB - negative values
amluiz
amommendes at hotmail.com
Fri Aug 9 21:48:07 CEST 2013
Thanks Philippi, it worked well...
Best,
Amom
Date: Fri, 9 Aug 2013 10:07:28 -0700
From: ml-node+s2731867n7584381h27 at n2.nabble.com
To: amommendes at hotmail.com
Subject: Re: plotRGB - negative values
Oops, one slight mistake: range() returns a vector of min,max values, so
you need to subtract them:
Ranges <- Ranges[,2] - Ranges[,1]
On Fri, Aug 9, 2013 at 10:02 AM, Tom Philippi <[hidden email]> wrote:
> Amom--
> If your PCA axis scores are centered (mean=0) as is customary, simply
> standardize each one to range -0.5:0.5 or -128:127 (with floor to convert
> to integers), and then add 0.5 or 128 to center at 0.5 or 127.
> Assuming that you're trying to false-color plot the first 3 PCA axes, the
> decision you need to make is whether you want to standardize each axis
> independently, so that each ranges from 0:255, or whether you want to
> standardize the axis with the greatest range to 0:255, then use that
> scaling on the other 2 axes to reflect their reduced variation. Either way
> is 'correct', they emphasize different variation in your data.
>
> Depending on the format of your PCA data, you may need to *apply the range
> function. If PCA is an X by 3 matrix with PCA axes as columns, something
> like:
> Ranges <- apply(PCA,FUN=range,MARGIN=2)
> scaledPCA <- scale(PCA,center=rep(-.5,3),scale=Ranges)
> should work.
> If you want all axes scaled by the longest axis, then something like:
> maxRange <- max(apply(PCA,FUN=range,MARGIN=2))
> scaledPCA <- scale(PCA,center=rep(-0.5,3),scale=rep(maxRange,3))
> might work. [Note that you could modify this if you needed to scale by
> eigenvalues.]
>
> If your PCA values are already in a RasterStackBrick object named
> PCAbrick, scale has a method for Raster* objects, but you need to use
> cellStats rather than apply and range:
> Ranges <- cellStats(PCAbrick,stat='range')
> scaledPCAbrick <- scale(PCAbrick,center=c(-0.5,3),scale=Ranges)
> [If your raster is "very large", you might have to call cellStats
> separately for max and min instead of once for range: see ?cellStats.]
>
> I hope that this is sufficient guidance, and that you can fix any errors
> in my untested code.
>
> Tom
>
>
>
>
> On Fri, Aug 9, 2013 at 9:02 AM, amluiz <[hidden email]> wrote:
>
>>
>>
>> Thanks Etienne
>> I was trying to plot three PCA axes (each one representing R, G and B
>> color bands) in the map, but without success in R. I only can do this in
>> GIS software...
>> Any suggestion?
>>
>> Date: Tue, 6 Aug 2013 13:51:55 -0700
>> From: [hidden email]
>> To: [hidden email]
>> Subject: Re: plotRGB - negative values
>>
>>
>>
>> Amom, you could probably offset your values and make sure you set
>> scale to
>>
>> the right value. If your lowest value is 1 and the highest value then
>>
>> becomes 2, then something like
>>
>> plotRGB(all.pca + 1, scale = 2)
>>
>>
>> I don't think you can use negative values in plotRGB.
>>
>>
>> Etienne
>>
>>
>>
>> 2013/8/6 amluiz <[hidden email]>
>>
>>
>> > Hello,
>>
>> >
>>
>> > I'm trying to use plotRGB. But I've negative values in my rasters cells
>> and
>>
>> > I get the following error:
>>
>> >
>>
>> > plotRGB(all.pca)
>>
>> > Error in rgb(RGB[, 1], RGB[, 2], RGB[, 3], alpha = alpha, max = scale) :
>>
>> > color intensity -1, not in 0:255
>>
>> >
>>
>> > Is there some way to solve this?
>>
>> >
>>
>> > Thanks in advance,
>>
>> >
>>
>> > Amom
>>
>> >
>>
>> >
>>
>> >
>>
>> >
>>
>> >
>>
>> > --
>>
>> > View this message in context:
>>
>> >
>> http://r-sig-geo.2731867.n2.nabble.com/plotRGB-negative-values-tp7584356.html
>> > Sent from the R-sig-geo mailing list archive at Nabble.com.
>>
>> >
>>
>> > _______________________________________________
>>
>> > R-sig-Geo mailing list
>>
>> > [hidden email]
>>
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> >
>>
>> [[alternative HTML version deleted]]
>>
>>
>> _______________________________________________
>>
>> R-sig-Geo mailing list
>>
>> [hidden email]
>>
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> If you reply to this email, your message will be added to
>> the discussion below:
>>
>> http://r-sig-geo.2731867.n2.nabble.com/plotRGB-negative-values-tp7584356p7584357.html
>>
>>
>>
>> To unsubscribe from plotRGB - negative values, click here.
>>
>> NAML
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://r-sig-geo.2731867.n2.nabble.com/plotRGB-negative-values-tp7584356p7584378.html
>> Sent from the R-sig-geo mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>
[[alternative HTML version deleted]]
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
If you reply to this email, your message will be added to the discussion below:
http://r-sig-geo.2731867.n2.nabble.com/plotRGB-negative-values-tp7584356p7584381.html
To unsubscribe from plotRGB - negative values, click here.
NAML
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/plotRGB-negative-values-tp7584356p7584382.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
More information about the R-sig-Geo
mailing list