ggplot2绘制嵌套圆图
2023-02-18 16:35:31 时间
❝本节来介绍如何使用「ggplot2」来绘制嵌套圆形图,图形绘制倒也简单主要是细节的调整结果仅供参考❞
加载R包
library(tidyverse)
导入数据
bytes_total <- read_csv("bytes_total.txt")
speed_index <- read_csv("speed_index.txt")
数据清洗
mobile_bytes <- bytes_total %>%
filter(date %in% c("2022_10_01", "2018_10_01"), client == "mobile") %>%
select(measure, date, p50, p90) %>%
pivot_longer(c(p50, p90), names_to = "percentile") %>%
mutate(year = str_sub(date, 1, 4)) %>%
mutate(name = paste(percentile, year, sep = "_")) %>%
mutate(x = c(0.45, 1, -0.57, -1)) %>%
mutate(label = case_when(percentile == "p50" ~ paste0("Peso\nmediano:\n", round(value), " KB"),
percentile == "p90" ~ paste0("Percentil 90:\n", round(value), " KB"))) %>%
mutate(x_label = c(0.45, 1.4, -0.57, -1.3))
数据可视化
ggplot() +
geom_point(aes(x = x, size = value, color = year), y = 0, alpha = 0.5,
data = filter(mobile_bytes, percentile == "p90")) +
geom_point(aes(x = x, size = value, color = year), y = 0,
data = filter(mobile_bytes, percentile == "p50")) +
geom_text(aes(x = x_label, label = label), y = 0.4, size = 2.5,
data = filter(mobile_bytes, percentile == "p90")) +
geom_text(aes(x = x_label, label = label), y = 0, size = 2.5,
data = filter(mobile_bytes, percentile == "p50")) +
annotate("text", x = -1, y = 1.3, label = "Octubre 2018",size = 3.5) +
annotate("text", x = 1, y = 1.3, label = "Octubre 2022", size = 3.5) +
labs(x = NULL,y = NULL) +
scale_color_manual(values = c("#1b998b", "#fb6107")) +
scale_x_continuous(limits = c(-2, 2)) +
scale_y_continuous(limits = c(-1.0, 1.4)) +
scale_size_area(max_size = 82) +
coord_equal() +
theme(
plot.title = element_text(hjust = 0.5, size = 18),
plot.caption = element_text(hjust = 0.5,size = 7),
panel.background = element_blank(),
panel.grid = element_blank(),
axis.ticks = element_blank(),
axis.text = element_blank(),
legend.position = "none")
相关文章
- 优思学院|六西格玛管理六步法的迷思和正解
- 如何制作gif图片?如何制作你项目的动态效果图到你的csdn?
- 高可用架构和系统设计经验
- 我终于统一了团队的技术方案设计模板
- SVN提示locked解决办法
- Edittext In Listview,当listview的item中有edittext时,怎么保存edittext的值?
- setOnTouchListener使用记录
- 异常的出现情况及解决方式(持续更新中)
- xUtils 的 post和get 请求 使用记录
- 在代码修改textview的Drawable 和 使用webview 加载网页
- 修改魅族和小米状态栏的文字颜色
- 自定义View实战(一) 汽车速度仪表盘
- 自定义View实战(二)QQ健康水滴形加载
- java.lang.UnsatisfiedLinkError 解决方法
- Material Design之CollapsingToolbarLayout 相关属性和方法介绍
- MaterialDesign之Dialog
- 在友盟分享的基础上集成微信登录
- 关于魅族手机 安装APP提示安装失败 更新包不兼容的解决方法
- java.lang.ExceptionInInitializerError 错误 解决方案
- Error in swirlExpectation(condition(object))