如何提高色标下端的分辨率?

时间:2015-10-26 19:19:17

标签: r ggplot2

我有一个连续变量区域,我使用以下代码

绘制
library(RColorBrewer)
library(maps)
usamap <- map_data("state")
myPalette <- colorRampPalette(rev(brewer.pal(10, "Spectral")))

ggplot() + 
  geom_polygon( data=usamap, aes(x=long, y=lat,group=group),colour="black", fill="white" )+
  geom_point(data=all,aes(x=lon,y=lat,color=area))+
  scale_colour_gradientn(name = "Slope",colours = myPalette(100))+
  coord_map(projection = "mercator")+
  theme_bw()+
  theme(legend.position = c(.90,.17),
        panel.grid.major = element_line(colour = "#808080"),
        axis.text.x = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks = element_blank())

Plot of Slope

但是正如您所看到的,大多数数据都在范围的下方,这会扭曲&#34;风景。如何向下移动色标?因此黄色部分向下移动,我可以看到颜色更加多样化?我不想转换数据,只改变色标。

数据

    structure(list(area = c(1310.534, 10385.8523, 7163.9071, 1610.9726, 
11152.4888, 1748.242, 7378.8761, 468.7878, 647.497, 81.5846, 
40.1448, 17.4565, 19.917, 62.6777, 95.0526, 142.1903, 61.3827, 
88.7848, 19.2695, 29.0079, 25.1229, 89.0956, 13.4679, 169.3852, 
18.3112, 1240.6043, 1722.3421, 1784.5018, 341.8784, 836.5662, 
45.8428, 821.0262, 3359.2146, 458.4279, 1522.913, 9538.9262, 
3480.944, 587.9273, 4325.2801, 1162.9047, 411.8081, 13183.0395, 
69.4117, 437.708, 984.1955, 284.1994, 416.9881, 404.0381, 1727.5221, 
466.1979, 180.7294, 722.6067, 523.1776, 336.6985, 141.9313, 701.8868, 
621.5971, 3167.5555, 1367.5137, 16.5759, 1219.8844, 117.5855, 
1388.2336, 3706.273, 562.0274, 499.8677, 96.8656, 7769.9643, 
3071.7259, 1572.1228, 1691.2622, 652.677, 574.9774, 8062.633, 
717.4267, 1390.8236, 1010.0954, 1590.2527, 349.6484, 4203.5507, 
927.2157, 4674.9285, 6412.8106, 813.2563, 4788.888, 59.8287, 
3418.7843, 3385.1145, 19766.7893, 709.6567, 437.708, 24687.7667, 
37992.5356, 69.6707, 437.708, 20321.0467, 4817.3779, 9207.4077, 
8396.7415, 2504.5185), lon = c(-109.195556, -109.309722, -109.295278, 
-109.441667, -110.920833, -111.302778, -110.499167, -119.449167, 
-119.448889, -119.671667, -119.797222, -119.943889, -119.8575, 
-119.994444, -119.971389, -119.990556, -119.968889, -120.026111, 
-120.1175, -120.161111, -120.156667, -119.722222, -119.804722, 
-119.832778, -119.659167, -122.748889, -117.403333, -117.448611, 
-117.18, -122.686111, -117.023333, -116.95, -121.208889, -122.956111, 
-123.881944, -123.554167, -123.411111, -122.727778, -123.397222, 
-122.947222, -123.333333, -120.005556, -122.506667, -124.069444, 
-123.6625, -122.768889, -123.723889, -123.709167, -123.754167, 
-123.845833, -123.281944, -121.547222, -123.886111, -123.651389, 
-123.742222, -124.186111, -123.233333, -116.324444, -123.181389, 
-119.802778, -120.305556, -116.622222, -121.044167, -120.926667, 
-121.087222, -121.727778, -122.188333, -121.878333, -121.596667, 
-121.428889, -123.013889, -118.926389, -123.889722, -124.098611, 
-124.05, -123.775, -120.683333, -124.075, -109.390556, -109.231667, 
-105.696111, -109.840833, -112.700833, -111.540556, -111.511111, 
-107.403056, -111.931667, -111.551944, -112.329722, -104.9825, 
-104.762778, -111.595833, -111.419722, -103.363611, -103.195556, 
-107.888333, -102.013056, -100.858056, -111.888889, -104.511667
), lat = c(33.290833, 32.965833, 33.049444, 33.064444, 33.619444, 
33.98, 33.798056, 38.379722, 38.513333, 38.793889, 39.113333, 
39.240278, 39.354444, 39.524444, 38.92, 38.9225, 38.903339, 38.848611, 
39.051944, 39.1075, 39.132222, 39.165028, 39.176389, 38.769722, 
38.716944, 45.233333, 47.784722, 47.652778, 46.7325, 45.244444, 
46.731944, 46.915278, 45.756667, 44.093056, 44.0625, 43.586111, 
43.272222, 43.35, 43.133333, 42.930556, 44.526389, 44.793889, 
45.477778, 42.891667, 42.231944, 44.712222, 45.476111, 45.446389, 
45.704167, 45.266667, 45.807222, 45.655556, 44.715278, 46.651111, 
46.374167, 42.123611, 44.783333, 47.555, 45.205833, 34.445, 34.893889, 
32.834722, 38.500278, 41.406111, 35.896667, 36.474444, 37.423333, 
42.565, 36.900278, 36.851944, 41.640833, 34.441667, 40.480556, 
40.491667, 41.299444, 40.181944, 35.628611, 41.791667, 48.578889, 
48.649444, 48.990278, 48.526667, 45.526667, 47.560833, 47.525833, 
44.508056, 47.5025, 47.930278, 45.6125, 39.438333, 39.355833, 
45.897778, 46.146111, 43.761111, 43.828056, 46.994722, 39.671944, 
38.794722, 48.427222, 48.672778)), .Names = c("area", "lon", 
"lat"), row.names = c(NA, -100L), .internal.selfref = <pointer: 0x0000000000350788>, class = c("data.table", 
"data.frame"))

1 个答案:

答案 0 :(得分:2)

您可以使用values参数来定义100种颜色之间的中断位置。这可用于制作非线性色标。 ?scale_colour_gradientn建议使用rescale以方便使用。 (或者您可以使用trans参数或limits参数,请阅读manual)。例如:

# Make up data    
all <- data.frame(lon = runif(1000, min(usamap$long), max(usamap$long)),
                      lat = runif(1000, min(usamap$lat), max(usamap$lat)),
                      var = rpois(1000, 1))

ggplot() + 
  geom_polygon( data=usamap, aes(x=long, y=lat,group=group),colour="black", fill="white") +
  geom_point(data=all,aes(x=lon,y=lat,color=var)) +
  scale_colour_gradientn(name = "Slope", colours = myPalette(100), 
                         values = scales::rescale((1:100)^1.5)) +
  coord_map(projection = "mercator") +
  theme_bw()+
  theme(legend.position = c(.90,.17),
        panel.grid.major = element_line(colour = "#808080"),
        axis.text.x = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks = element_blank())

enter image description here