r - 如何为 scale_fill_distiller 设置颜色条
问题描述
我正在绘制一个“圆圈包装图”,圆圈的颜色映射到一个值:
# libraries
library(packcircles)
library(ggplot2)
# Create data
data=data.frame(group=paste("Group", letters[1:20]), value=sample(seq(1,100),20))
# Generate the layout. This function return a dataframe with one line per bubble.
# It gives its center (x and y) and its radius, proportional of the value
packing <- circleProgressiveLayout(data$value, sizetype='area')
# We can add these packing information to the initial data frame
data = cbind(data, packing)
# Check that radius is proportional to value. We don't want a linear relationship, since it is the AREA that must be proportionnal to the value
plot(data$radius, data$value)
# The next step is to go from one center + a radius to the coordinates of a circle that
# is drawn by a multitude of straight lines.
dat.gg <- circleLayoutVertices(packing, npoints=50)
dat.gg$value=rep(data$value, each=51)
# Make the plot
ggplot() +
# Make the bubbles
geom_polygon(data = dat.gg, aes(x, y, group = id, fill=value), colour = "black", alpha = 0.6) +
scale_fill_distiller(palette = "BuPu", direction = 1 , guide="colourbar") +
# Add text in the center of each bubble + control its size
geom_text(data = data, aes(x, y, size=value, label = group)) +
scale_size_continuous(range = c(1,4)) +
# General theme:
theme_void() +
theme(legend.position="none") +
coord_equal()
我想在绘图旁边显示一个颜色条,所以我尝试了这条线:
scale_fill_distiller(palette = "BuPu", direction = 1 , guide="colourbar")
但这不起作用(不显示彩条)。什么是正确的语法?
解决方案
推荐阅读
- vertx-httpclient - vertx clienthttp 在负载下给出“尝试回收超过允许的范围”?
- java - 将字节缓冲区反序列化为 Avro
- postgresql - 是否可以在目录下创建模式?
- vue-cli - 在 webpack 中使用 multi-entry 时分块的条件是什么?
- c++ - 如何在 Ubuntu 上使用 mingw 和 openssl 库进行交叉编译?
- c# - 为公共 SaaS 运行的 C#/.NET 自定义脚本,无法访问本地文件,特定自定义功能 .net 核心权限
- go - 使用Fiber,Golang返回像json这样的数组
- c# - 防止在字典c#中作为值添加的对象的重复变量
- scikit-learn - 应用欠采样技术来训练和测试数据
- json - 如何将_JsonMap转换为flutter / dart中的对象