Dear list members,

I am doing a kernel using stat_density2d (ggplot2) and ggmap, but the
density at the scale (guide_colorbar) gave me numbers higher than 1. I was
thinking that the scale should between 0 and 1.

 > dput(mam)
structure(list(Especie = structure(c(5L, 4L, 16L, 16L, 11L, 16L,
8L, 15L, 16L, 16L, 17L, 16L, 16L, 8L, 5L, 32L, 16L, 16L, 16L,
11L, 16L, 10L, 29L, 11L, 33L, 34L, 22L, 33L, 16L, 5L, 11L, 16L,
5L, 16L, 8L, 10L, 11L, 11L, 14L, 35L, 11L, 33L, 16L, 8L, 33L,
33L, 33L, 10L, 17L, 21L, 33L, 11L, 11L, 11L, 13L, 16L, 16L, 5L,
33L, 33L, 16L, 17L, 21L, 33L, 16L, 16L, 16L, 8L, 8L, 29L, 20L,
21L, 21L, 5L, 35L, 6L, 11L, 11L, 11L, 17L, 16L, 11L, 6L, 18L,
12L, 1L, 9L, 24L, 9L, 25L, 33L, 30L, 28L, 23L, 12L, 33L, 26L,
2L, 7L, 4L, 19L, 33L, 33L, 3L, 33L, 33L, 12L, 12L, 33L, 15L,
15L, 23L, 12L, 33L, 20L, 12L, 12L, 34L, 12L, 12L, 12L, 9L, 15L,
33L, 15L, 31L, 6L, 27L, 16L, 16L, 12L, 17L, 31L, 15L), .Label = c("Artibeus
sp",
"Balantiopteryx p", "Caluromys", "Caluromys derbianus", "Canis familiaris",
"Dasyprocta punctata", "Dasypus novecintus", "Dasypus novemcinctus",
"Dasypus novemcintus", "Didelphis marsupialis", "Didelphis sp",
"Didelphis virginiana", "Felis catus", "Leopardus pardalis",
"Liomys salvini", "Mamifero sp", "Mephitis macriura", "Nasua narica",
"Odocoileus virginianus", "Procyon lotor", "Quiroptero", "Rat\xf3n",
"Rattus rattus", "Rodentia", "Rodentia o Didelphis", "Roedor",
"Roedores 2", "Saccopteryx sp", "Sciurus sp", "Sciurus variegatoides dor",
"Sigmodon hispidus", "Spilogale putorius", "Sylvilagus floridanus",
"Tamandua mexicana", "Urocyon cinereoargenteus"), class = "factor"),
    X.coord = c(322987.95952, 325730.6232, 321659.7367, 322918.3029,
    323609.09467, 325512.19525, 323764.38459, 324763.2989, 324776.86565,
    325604.98661, 323096.20206, 330310.82626, 324767.67287, 323765.25563,
    322674.86773, 328135.2967, 324597.78273, 324600.87305, 324632.33775,
    328660.52561, 324591.9991, 323766.44494, 321216.67628, 324825.73645,
    321184.10359, 327958.75264, 323761.64218, 324025.92506, 324786.91913,
    329580.0051, 322995.60355, 323973.76564, 321493.19176, 324785.03482,
    324778.44835, 329303.04054, 322610.7403, 328678.35353, 323197.25519,
    328158.76743, 323871.30514, 321458.97281, 324770.21768, 325306.7613,
    321430.78178, 321433.43279, 324888.29316, 322594.28031, 331175.66318,
    324066.02774, 324775.3186, 324414.2447, 328675.32306, 328992.56438,
    331154.9004, 324935.468, 326805.06838, 323391.42452, 324749.94415,
    324088.94963, 323766.39105, 322715.33621, 324500.68551, 324555.64195,
    324779.32112, 324780.00484, 322886.55745, 324776.59626, 331073.98966,
    326828.94738, 324843.45543, 324380.88867, 324752.33179, 322867.97954,
    331130.21877, 326203.79357, 321987.54129, 323662.97111, 324590.02822,
    331052.21956, 324722.39324, 330683.30218, 321451.03001, 322019.75246,
    324698.98168, 322676.80361, 331793.94275, 324052.52736, 324481.32496,
    329028.76756, 330076.6977, 327276.82369, 330780.34186, 324553.96619,
    322496.84561, 329722.67374, 321975.53717, 324895.30751, 328102.05257,
    321414.63336, 322194.27617, 331059.78857, 329479.08312, 324777.4264,
    322481.58752, 322959.49845, 324783.88609, 328037.44529, 323038.3676,
    330541.50841, 328200.81307, 324553.96619, 322496.84561, 329722.67374,
    329027.50558, 324776.74167, 321494.82482, 321948.37204, 322338.63361,
    326278.17193, 326559.13612, 328125.1979, 328679.30886, 322722.02604,
    322722.02604, 324771.51664, 324762.7548, 324373.39821, 328017.32502,
    328056.96015, 328658.34473, 329748.63475, 330347.62649, 331250.12549
    ), Y.coord = c(1212816.72267, 1203589.87118, 1216664.97177,
    1213155.59099, 1211596.91621, 1203657.06277, 1210512.82004,
    1207236.2534, 1206081.54143, 1203733.18333, 1212434.44835,
    1197641.90635, 1206971.07739, 1210499.80476, 1214126.51821,
    1200822.80165, 1207998.27613, 1208007.24999, 1207951.91019,
    1199810.14931, 1208020.34456, 1210518.80261, 1219879.10104,
    1204247.14111, 1219823.39763, 1202700.43187, 1210538.86054,
    1209649.78376, 1204570.6866, 1198603.53572, 1212780.62796,
    1209837.39685, 1220217.51102, 1205189.01432, 1205433.20157,
    1199024.4562, 1214317.25625, 1199791.96517, 1212234.3398,
    1200869.59233, 1210097.54661, 1218098.73416, 1206925.02914,
    1203723.12563, 1217680.79515, 1217745.803, 1204098.44844,
    1214482.50603, 1196706.9835, 1209356.23693, 1205420.22606,
    1208355.27597, 1199788.99364, 1199394.68503, 1196396.04844,
    1204012.93945, 1203286.10706, 1211941.25749, 1207604.57008,
    1209145.90293, 1210412.74919, 1213971.03438, 1208194.33759,
    1208086.73847, 1205925.43906, 1205994.4668, 1213282.97289,
    1205448.22742, 1196917.0767, 1203272.86475, 1204217.95135,
    1208421.64028, 1207643.56592, 1213326.18024, 1196836.48801,
    1202574.69992, 1220828.8802, 1200573.76846, 1208023.36563,
    1196941.30151, 1207751.91699, 1197269.07522, 1218104.81679,
    1215769.60346, 1207739.48286, 1214012.51612, 1193961.91999,
    1209404.57935, 1208148.42958, 1199284.93476, 1197746.8724,
    1203069.91842, 1197118.16228, 1207612.71539, 1214088.20498,
    1198081.52233, 1216153.3861, 1204017.96867, 1202058.3923,
    1217381.96472, 1221262.49361, 1196871.43382, 1198686.39568,
    1205771.79279, 1214672.36896, 1212851.40302, 1205814.5788,
    1200372.39266, 1212512.94983, 1197340.09056, 1200916.2513,
    1207612.71539, 1214088.20498, 1198081.52233, 1199289.1725,
    1206150.95542, 1216894.88962, 1216209.29497, 1215391.85521,
    1203353.03736, 1202935.60485, 1200693.14035, 1199713.97172,
    1213719.97641, 1213715.75457, 1206167.64173, 1204978.63437,
    1202185.56031, 1202497.54629, 1202301.77273, 1199717.46716,
    1198125.39547, 1197486.94918, 1195105.87025)), .Names = c("Especie",
"X.coord", "Y.coord"), class = "data.frame", row.names = c(NA,
-134L))


# con ggmap

mapa <- get_map(location = c(lon = -85.55, lat = 11),  zoom = 10)
ggmap(mapa)

mam.spdf <- SpatialPointsDataFrame(coords = mam[, 2:3], proj4string =
CRS("+proj=tmerc +lat_0=0 +lon_0=-84 +k=0.9999 +x_0=500000 +y_0=0
+ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"), data = mam)
mam.spdf
mam.cg <- spTransform(mam.spdf, CRS("+proj=longlat +datum=WGS84"))
mam.cg

mam.cg.df <- as.data.frame(mam.cg)
mam.cg.df

ggmap(mapa) + geom_point(data = mam.cg.df, aes(x=X.coord.1, y=Y.coord.1),
colour= "red")

ggmap(mapa, extent = "device") + stat_density2d(aes(x = X.coord.1, y =
Y.coord.1, fill = ..level..,alpha = ..level..), size = 2, bins = 4, data =
mam.cg.df, geom = "polygon") +
  scale_fill_gradient("Density") +
  scale_alpha(range = c(.4, .75), guide = FALSE) +
  guides(fill = guide_colorbar(barwidth = 1.5, barheight = 10))


Manuel

-- 
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspinola@una.ac.cr
mspinola10@gmail.com
Teléfono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de río <https://sites.google.com/site/lobitoderio/>
Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/>

	[[alternative HTML version deleted]]

