如何在ggplot中创建气泡网格图?

编程入门 行业动态 更新时间:2024-10-15 10:16:26
本文介绍了如何在ggplot中创建气泡网格图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想用ggplot创建气泡网格图.像这样的东西:

I want to create bubble grid charts with ggplot. somthing like this:

我在网上找不到任何代码或示例.

I couldnt find any code or exampe online.

谢谢

推荐答案

使用具有离散x和y比例的 geom_point 可以帮助您入门.这是一个包含一些快速玩具数据的示例:

Using geom_point with discrete x and y scales will get you started. Here's an example with some quick toy data:

library(tidyverse) offenses <- c("robbery", "violence", "drugs") actions <- c("formal", "informal", "considered") counts <- sample(10:100, 9, replace = TRUE) data <- expand.grid(offenses = offenses, actions = actions) %>% bind_cols(counts = counts) ggplot(data, aes(x = str_to_title(offenses), y = str_to_title(actions), colour = str_to_title(offenses), size = counts)) + geom_point() + geom_text(aes(label = counts), colour = "white", size = 3) + scale_x_discrete(position = "top") + scale_size_continuous(range = c(10, 30)) + # Adjust as required. scale_color_brewer(palette = "Set2") + labs(x = NULL, y = NULL) + theme(legend.position = "none", panel.background = element_blank(), panel.grid = element_blank(), axis.ticks = element_blank())

根据需要使用 scale_size_continouous 的 range 参数来获得适合您数据集大小的气泡.

Play around with the range parameter of scale_size_continouous as needed to get bubbles of a reasonable size for your data set.

更多推荐

如何在ggplot中创建气泡网格图?

本文发布于:2023-11-04 18:15:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1558662.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网格   气泡   如何在   ggplot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!