[R-sig-Geo] help with 2d- Density plots (ggplot2)

Thierry Onkelinx thierry.onkelinx at inbo.be
Mon Jan 18 09:35:59 CET 2016


Just loop over the species columns and use them to subset the data

nc <- get_map("Persian Gulf", zoom = 6, maptype = 'terrain', language =
"English")
ncmap <- ggmap(nc,  extent = "device")
extra_map <-     geom_point(data=this_species, aes(x=long, y=lat))+
    geom_point(aes(x =50.626444, y = 26.044472), color="red", size = 4)+
    scale_fill_gradient(low = "green", high = "red") + scale_alpha(range =
c(0.00, 0.25), guide = FALSE)

# assuming SP1 is the 3rd column
for (i in 2 + seq_len(n_species)) {
    this_species <- sample.data3[sample.data3[, i] > 0, ]
   p <- ncmap +
    stat_density2d(data=this_species, aes(x=long, y=lat, fill=..level..,
alpha=..level..),geom="polygon") +
    extra_map
    print(p)
}

Best regards,

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2016-01-17 0:39 GMT+01:00 Amao Abduljamiu <lekisoft at gmail.com>:

> Yes Sir, my plan is to have several maps .i.e a map for each species.
>
> Sent from my iPad
>
> On Jan 16, 2016, at 10:18 PM, Thierry Onkelinx <thierry.onkelinx at inbo.be>
> wrote:
>
> Dear Amao,
>
> It's not clear how the "hundreds of species" come into the play. Do you
> want a map for each species? Or rather a single map that combines the
> species info.
>
> ggplot2() has AFAIK no options to restrict the output of stat_bin2d() to a
> polygon.
>
> Best regards,
>
>
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
> Forest
> team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
> Kliniekstraat 25
> 1070 Anderlecht
> Belgium
>
> To call in the statistician after the experiment is done may be no more
> than asking him to perform a post-mortem examination: he may be able to say
> what the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does not
> ensure that a reasonable answer can be extracted from a given body of data.
> ~ John Tukey
>
> 2016-01-15 18:00 GMT+01:00 Amao Abduljamiu <lekisoft at gmail.com>:
>
>> Dear All,
>>
>> I need help with 2d- Density plots (ggplot2)...
>>
>> I'm trying to plot ecological distribution of some species of organisms
>> i'm
>> studying over the Arabian/Persian Gulf. Here is a sample of code i've
>> tried,
>>
>> Backround layer
>>
>> nc <- get_map("Persian Gulf", zoom = 6, maptype = 'terrain', language =
>> "English")
>> ncmap <- ggmap(nc,  extent = "device")
>>
>> Other layers
>>
>>   ncmap+
>>     stat_density2d(data=sample.data3, aes(x=long, y=lat, fill=..level..,
>> alpha=..level..),geom="polygon")+
>>     geom_point(data=sample.data3, aes(x=long, y=lat))+
>>     geom_point(aes(x =50.626444, y = 26.044472), color="red", size = 4)+
>>     scale_fill_gradient(low = "green", high = "red") + scale_alpha(range =
>> c(0.00, 0.25), guide = FALSE)
>>
>> but , i will like to use the stat_density2d to show the distributions of
>> hundreds of species (which are recorded in columns e.g SP1....SPn) over
>> the
>> water body rather than just displaying latitude and longitude.
>>
>> Also, is it possible to restrict my heat map to just the water body ? I'll
>> appreciate any help and recommendations i can get on this please
>>
>> I will also appreciate any suggestion on alternative way to achieve this.
>>
>>
>> Here is a link to stackoverflow where I initially asked the question with
>> an
>> image of what the problem look like.
>>
>>
>> http://stackoverflow.com/questions/34569152/ggplot-stat-density2d-plots-for-
>> ecological-distribution
>> <http://stackoverflow.com/questions/34569152/ggplot-stat-density2d-plots-for-ecological-distribution>
>>
>> Sincerely
>> Amao
>> -------------------------------------------
>> Amao Abduljamiu O.
>> PhD Candidate - Geology
>> Earth Sciences Department
>> King Fahd University of Petroleum and Minerals (KFUPM)
>> Dhahran, Saudi Arabia
>> P. O. Box 1723 KFUPM, Dhahran 31261 Saudi Arabia
>> Tel. office +966 3 860 3240
>> Mobile: +966 535467527
>> Skype: lakesido02
>> Email: amao at kfupm.edu.sa
>> Alt: lekisoft at gmail.com
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list