descriptive

整个新系列。目前的几个系列, #R实战  以生信分析为主, #跟着CNS学作图复现顶刊Figure为主,而本系列 #R绘图 则是学习不在文章中但同样很好看的图,致力于给同学们在数据可视化中提供新的思路和方法。

本期图片

描述统计图

示例数据和代码领取

点赞在看 本文,分享至朋友圈集赞20个保留30分钟,截图发至微信mzbj0002领取。

木舟笔记2022年度VIP可免费领取

木舟笔记2022年度VIP企划

权益:

  1. 2022年度木舟笔记所有推文示例数据及代码(在VIP群里实时更新)。

  2. 木舟笔记科研交流群

  3. 半价购买跟着Cell学作图系列合集(免费教程+代码领取)|跟着Cell学作图系列合集。

收费:

99¥/人。可添加微信:mzbj0002 转账,或直接在文末打赏。

绘制

数据处理

library('tidyverse')
# install.packages('janitor')
library('janitor')
library('readxl')
library('lubridate')
ppa_price <- read_excel("2021_utility-scale_solar_data_update_0.xlsm", sheet = "PPA Price by Project (PV only)", range = "A24:L357"
)
str(ppa_price)
# 长宽转换
ppa_price_long <- ppa_price %>% pivot_longer(cols = c(CAISO:Hawaii),names_to = "region", values_to = "price", values_drop_na = TRUE)
# 列名清洗
ppa_price_long <- ppa_price_long %>%clean_names()
# Convert Region to Factor
ppa_price_long <- ppa_price_long %>%mutate(region_cat = factor(region, ordered = TRUE))# 提取年份
str(ppa_price_long)
ppa_price_long <- ppa_price_long %>% mutate_if(is.POSIXct, as_date) %>%  # 日期格式为POSIXctmutate(ppa_year = year(ppa_execution_date))

散点图

# 颜色设置
color.pal <- c("#4E79A7", #dark blue"#F28E2B", #orange"#E15759", #red"#76B7B2", #teal"#59A14F", #green"#BAB0AC", #gray"#B07AA1", #purple"#FF9DA7", #pink"#9C755F", #brown"#EDC948" #yellow
)## 散点图
p1 <- ppa_price_long %>% ggplot(aes(x = ppa_execution_date,y = price,size = capacity_mw,color = region))+geom_point(shape = 1, stroke = 1.2)+scale_size(guide = "none")+scale_color_manual(values = color.pal, name = "Region")+#ggthemes::scale_color_tableau()+scale_x_date(date_breaks = "2 years", date_labels = "%Y")+ # x轴日期间距及格式ylab("PPA Price (2020 $/MWh)")+theme_light()+theme(panel.grid.major.x = element_blank(),panel.grid.minor.x = element_blank(),panel.grid.minor.y = element_blank(),panel.border = element_blank(),axis.line.x.bottom = element_line(color = "lightgray"),axis.line.y.left = element_line(color = "lightgray"),axis.title.y = element_text(size = 10),axis.title.x = element_blank())+guides(color = guide_legend(override.aes=list(shape = 15)))p1

p1

堆叠柱状图

## 堆叠柱状图
year_totals <- ppa_price_long %>% group_by(ppa_year) %>% arrange(ppa_year, region) %>% summarise(year_total = prettyNum(trunc(sum(capacity_mw)),big.mark = ","),region = first(region))p2_data = ppa_price_long %>% group_by(region, ppa_year) %>% summarise(capacity_mw = sum(capacity_mw)) %>% left_join(year_totals)p2 <- p2_data %>% ggplot(aes(x = ppa_year,y = capacity_mw,color = region,fill = region,label = year_total))+geom_col(width = 0.7)+geom_text(position = position_stack(), vjust = -0.5, size = 3) +scale_fill_manual(values = color.pal)+scale_color_manual(values = color.pal)+scale_x_continuous(breaks = seq(2006, 2021, 1))+scale_y_continuous(limits = c(0, 3500), expand = c(0,0),labels = c("0K", "1K", "2K", "3K"),breaks = c(0, 1000, 2000, 3000))+ylab("Capacity (MW-AC)")+theme_light()+theme(legend.position = "top",axis.title.y = element_text(size = 10),panel.grid.major.x = element_blank(),panel.grid.minor.x = element_blank(),panel.grid.minor.y = element_blank(),panel.border = element_blank(),axis.line.x.bottom = element_line(color = "lightgray"),axis.line.y.left = element_line(color = "lightgray"),axis.title.x = element_blank(),axis.text.x = element_text(angle = 90))p2

p2

饼图

cumulative_cap <- ppa_price_long %>% group_by(region) %>% summarise(cumulative_capacity = round(sum(capacity_mw))) %>% mutate(capacity_label = prettyNum(cumulative_capacity, big.mark = ","))p3 <- ggplot(cumulative_cap,aes(x="",y=cumulative_capacity,fill=region))+geom_bar(stat="identity", width=1)+scale_fill_manual(values = color.pal)+coord_polar("y", start=0, direction = -1)+annotate("text", y = 4000, x = 1,label = "West (non-ISO)\n 7,919", size = 3)+annotate("text", y = 18000, x = 1.1,label = "CAISO \n 8,649", color = "white", size = 3)+annotate("text", y = 8800, x = 1.6,label = "Southwest (non-ISO) \n 2,538", size = 3)+annotate("text", y = 13000, x = 1.7,label = "ISO-NE \n 326", size = 3)+annotate("text", y = 11000, x = 1.7,label = "PJM \n 739", size = 3)+theme_void()+labs(caption = "Cumulative Capacity (MW-AC)")+theme(legend.position="top",legend.title = element_blank(),legend.key.size = unit(.5, 'cm'),plot.caption = element_text(hjust = .5),plot.title = element_text(hjust = 0.5, size = 12),plot.subtitle = element_text(hjust = 0.5, size = 10))+guides(fill = guide_legend(nrow = 5, byrow = TRUE))
p3

p3

拼图

library('ggpubr')
p_full <- ggarrange(ggarrange(p1, p2, nrow=2, legend = "none"), p3, widths = c(2, 1), heights = c(1,1))p_fullannotate_figure(p_full,top = text_grob("Utility-Scale Solar \n Power Purchase Agreement Prices for PV", face = "bold",size = 14, color = color.pal[1]),bottom = text_grob("Source: Berkeley Lab", hjust = 1,x = .9,face = "italic",size = 9,color = color.pal[1])
)

描述统计图

参考

  • Analytics X3: Tidy Tuesday US Solar | KPress R Blog(https://kpress.dev/blog/analytics-x3-tidytuesday-us-solar/)

往期内容

  1. (免费教程+代码领取)|跟着Cell学作图系列合集

  2. Q&A | 如何在论文中画出漂亮的插图?

  3. Front Immunol 复现 | 1. GEO数据下载及sva批次校正(PCA可视化)

  4. R绘图 | 气泡散点图+拟合曲线

  5. 跟着 Cell 学作图 | 桑葚图(ggalluvial)

  6. R绘图 | 对比条形图+连线

  7. R绘图 | 一幅小提琴图的美化之旅

木舟笔记矩阵

R绘图 | 描述性统计常用图(散点图+柱状图+饼图)相关推荐

  1. R语言描述性统计:使用mean函数计算dataframe数据中指定数据列的均值

    R语言描述性统计:使用mean函数计算dataframe数据中指定数据列的均值 目录 R语言描述性统计:使用mean函数计算dataframe数据中指定数据列的均值

  2. R绘图 | 堆叠柱状图

    stack_bar 整个新系列.目前的几个系列, 「#R实战」  以「生信分析」为主, 「#跟着CNS学作图」 以「复现顶刊」Figure为主,而本系列 「#R绘图」 则是学习不在文章中但同样很好看的 ...

  3. 国庆特惠 !| CNS图表复现|生信分析|R绘图 资源分享讨论群!

    cover ❝ Q:群里有哪些资源? A:2022.12.31前木舟笔记公众号更新的所有资源.(具体目录详见下方) Q:2022年都快结束了,现在加群不是亏了? A:无论什么时候加群,拿到的资源都是一 ...

  4. R绘图 vs Python绘图(散点图、折线图、直方图、条形图、箱线图、饼图、热力图、蜘蛛图)

    写在前面:为啥不用excel绘制这些图,用PoweBI,帆软BI等可视化软件来绘图,不是更方便吗?的确,这些工具都很方便,但同时,它们显得很呆,不够灵活,更为致命的是,它们绘制出的图形,分辨率不够,用 ...

  5. 应用统计学与R语言实现学习笔记(三)——描述性统计

    Chapter 3 Descriptive Statistics 本篇是第三章,内容是描述性统计.同时在这一章会开始渗透R语言的相关内容.但整体还是以理论为主. Chapter 3 Descripti ...

  6. R语言数据描述性统计(Descriptive statistics)实战:数据全局描述信息、数值数据的描述性统计(Numerical data)、离散型数据的描述性统计(Categorical)

    R语言数据描述性统计(Descriptive statistics)实战:数据全局描述信息.数值数据的描述性统计(Numerical data).离散型数据的描述性统计(Categorical) 目录

  7. R语言使用epiDisplay包的summ函数计算向量数据在不同分组下的描述性统计汇总信息并可视化有序点图(名称、有效值个数、均值、中位数、标准差、最大值、最小值)

    R语言使用epiDisplay包的summ函数计算向量数据在不同分组下的描述性统计汇总信息并可视化有序点图(名称.有效值个数.均值.中位数.标准差.最大值.最小值) 目录

  8. R绘图 | 圆角堆叠柱状图(ggchicklet )

    ggchicklet 整个新系列.目前的几个系列, #R实战  以生信分析为主, #跟着CNS学作图 以复现顶刊Figure为主,而本系列 #R绘图 则是学习不在文章中但同样很好看的图,致力于给同学们 ...

  9. R语言描述性统计分析:使用epiDisplay包的summ函数获取dataframe数据中每个变量的常用统计量、对每个变量进行汇总统计

    R语言描述性统计分析:使用epiDisplay包的summ函数获取dataframe数据中每个变量的常用统计量.对每个变量进行汇总统计 目录

最新文章

  1. lightgbm 决策树 可视化 graphviz
  2. XMLHelper.cs
  3. 微信研究员解析深度学习在NLP中的发展和应用
  4. MySQL-性能优化_大表和大事务的常用处理方案
  5. nssl1436-赛艇表演【最短路】
  6. 近期会将视频在线课堂移植ios,欢迎大家关注
  7. @PostConstruct、@PreDestroy注解介绍及Spring中@PostConstruct、constructor、@Autowired的顺序
  8. 重磅!阿里推出国产开源的 JDK!
  9. 企业发文的红头文件_实例分享:怎样制作双发文单位红头文件,文件二字与发文单位并排...
  10. 电信宽带华为HG8245光纤猫开路由、WIFI的破解办法
  11. 【格式化文档】ISO27001控制措施+ISO27002实施指南 【上】
  12. 调用链根因定位论文《Ranking causal anomalies by modeling local propagations on networked systems》
  13. 微信小程序如何保存图片到相册
  14. 计算机一级c云大,云南大学网红C位易主!新晋流量霸主竟然是……
  15. pdf java 开源_Java开源PDF类库 分类列表
  16. 七,springBoot-SpringBootApplication注解
  17. 金钱找零问题,招行笔试题
  18. 你必须知道的家庭急救常识
  19. 轻松bypass360网站卫士WAFSQL注入防护
  20. 用浏览器快速开启Docker的体验之旅

热门文章

  1. 从原厂官网和UltraLibrarian下载元器件封装
  2. Spring Security的几个重要词
  3. C语言 二维数组排序
  4. Python+matplotlib画爱心
  5. 假面科技披露赌博处理情况 狼人杀APP反赌系统将持续开发
  6. 2020中南大学计算机考研考科目,2020年考研院校篇——中南大学(总篇)
  7. 苏宁“百日会战” 动了谁的奶酪
  8. 这 9 个 Java 开源项目 yyds(转载)
  9. C语言:调整奇数偶数顺序
  10. 解决could not read Username for ‘https://gitee.com‘: Device not configured