r-如何在ggplot2中设置scale_colour_brewer()的指南大小?

时间:2017-08-13 11:56:29

标签: r ggplot2 ggmap

我使用ggmap在谷歌地图上绘制散点图。我想调整scale_colour_brewer()的指南字体大小。 数据看起来像这样

 shopGlng shopGlat shopPower
1  121.2149 31.04965        35
2  121.5595 31.22596        40
3  121.2326 31.00489        35
4  121.5184 31.22838        35
5  121.5160 31.15689        45
6  121.4557 31.26370        35
7  121.5009 31.25928        35
8  121.1749 30.89317        35
9  121.1990 31.04987        35
10 121.5977 31.26352        35

这是我的代码

library(ggplot2)
library(magrittr)
library(ggmap)

data = read.csv('file')

# ny_center <- geocode("new york", source = "google")
sh_center <- geocode("shanghai", source = "google")
map <- get_googlemap(
  zoom = 11,
  # Use Alternate New York City Center Coords
  center = sh_center %>% as.numeric,
  maptype = "hybrid",
  sensor = FALSE)

color <- as.character(data$shopPower/10)

p <- ggmap(map) +
  geom_point(size = 1,
             data = data,
             aes(x = shopGlng,
                 y = shopGlat,
                 color = color)) +
  xlab("") +
  ylab("") +
  scale_colour_brewer(palette = "Set1", guide = "legend")

p

结果如下:enter image description here

我想更改颜色条的字体大小。哪个参数显示我用来做这个?

1 个答案:

答案 0 :(得分:2)

您可以使用legend.textlegend.title来设置颜色条的字体大小。

p <- ggmap(map) +
     geom_point(size = 1,
                data = data,
                aes(x = shopGlng,
                    y = shopGlat,
                    color = color)) +
     xlab("") +
     ylab("") +
     scale_colour_brewer(palette = "Set1", guide = "legend")+
     theme(legend.text = element_text(size=15),
           legend.title = element_text(size=15)  )

enter image description here