R语言操作练习2

  1. 加载tidyr包,探索table1,table2,table3,table4a, table4b维度和结构

  2. 将table4a进行宽转长操作,列名为country,year,population

  3. 基于题2,以country为横坐标,population为纵坐标,fill=year,采用dodge形式作柱状图,颜色为#022a99和#fbcd08

  4. 基于题2,以country为横坐标,population为纵坐标,fill=year,作堆叠柱状图,颜色为#022a99和#fbcd08

  5. 基于题2,以country为横坐标,population为纵坐标,year作为分面对象,作分面柱状图,主题用theme_bw(),采用Pastel3填充country

  6. 基于题2,以country为横坐标,population为纵坐标,year作为分面对象,作分面柱状图,主题采用theme()

  7. 绘制参考范例中的和弦图

    https://jokergoo.github.io/circlize_book/book/the-chorddiagram-function.html#scaling

  8. 绘制参考范例中的峰峦图

    https://r-graph-gallery.com/294-basic-ridgeline-plot.html

r 复制代码
install.packages("tidyr")
install.packages("ggplot2")
install.packages("dplyr")
install.packages("RColorBrewer")
install.packages("circlize")
install.packages("ggridges")
library(ggridges)
library(tidyr)
library(ggplot2)
library(dplyr)
library(RColorBrewer)
library(circlize)
str(table1)
str(table2)
str(table3)
str(table4a)
str(table4b)
table4a_long <- table4a %>%
  pivot_longer(cols = -country, names_to = "year", values_to = "population")
ggplot(table4a_long, aes(x = country, y = population, fill = year)) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_manual(values = c("#022a99", "#fbcd08")) +
  theme_minimal()
ggplot(table4a_long, aes(x = country, y = population, fill = year)) +
  geom_bar(stat = "identity") +
  scale_fill_manual(values = c("#022a99", "#fbcd08")) +
  theme_minimal()
ggplot(table4a_long, aes(x = country, y = population, fill = country)) +
  geom_bar(stat = "identity") +
  scale_fill_brewer(palette = "Pastel3") +
  facet_wrap(~year, scales = "free_y") +
  theme_bw()
ggplot(table4a_long, aes(x = country, y = population, fill = country)) +
  geom_bar(stat = "identity") +
  facet_wrap(~year, scales = "free_y") +
  theme()
chord_data <- data.frame(
  from = c("A", "B", "C"),
  to = c("D", "E", "F"),
  value = c(10, 20, 30)
)
chordDiagram(chord_data, transparency = 0.5)
ridge_data <- data.frame(
  country = rep(c("Country1", "Country2"), each = 100),
  year = rep(rep(2000:2001, each = 50), times = 2),
  population = rnorm(200, mean = 100, sd = 20)
)
ridge_data$year <- as.factor(ridge_data$year)
ggplot(ridge_data, aes(x = population, y = year, fill = country)) +
  geom_density_ridges(alpha = 0.7, position = "identity", scale = 0.9) +
  scale_fill_manual(values = c("#022a99", "#fbcd08")) +
  labs(title = "Population Distribution by Country and Year",
       x = "Population", y = "Year") +
  theme_ridges()
相关推荐
Teacher.chenchong1 分钟前
现代R语言机器学习:Tidymodel/Tidyverse语法+回归/树模型/集成学习/SVM/深度学习/降维/聚类分类与科研绘图可视化
机器学习·回归·r语言
星座5281 小时前
基于现代R语言【Tidyverse、Tidymodel】的机器学习方法与案例分析
机器学习·r语言·tidyverse·tidymodel
Chef_Chen17 小时前
从0开始学习R语言--Day49--Lasso-Cox 回归
学习·回归·r语言
Rita的程序bug1 天前
R语言基础| 基本图形绘制(条形图、堆积图、分组图、填充条形图、均值条形图)
开发语言·信息可视化·r语言
青春不败 177-3266-05203 天前
基于现代R语言【Tidyverse、Tidymodel】的机器学习方法与案例分析实践技术应用
深度学习·机器学习·支持向量机·r语言·集成算法
医工交叉实验工坊4 天前
R 语言绘制 10 种精美火山图:转录组差异基因可视化
python·信息可视化·r语言
智算菩萨4 天前
传统机器学习在信用卡交易预测中的卓越表现:从R²=-0.0075到1.0000的华丽转身
人工智能·机器学习·r语言
2201_753054895 天前
应用回归分析,R语言,多元线性回归总结(下)
回归·r语言·线性回归
LabEx8 天前
科研数据可视化核心技术:基于 AI 与 R 语言的热图、火山图及网络图绘制实践指南
人工智能·信息可视化·r语言·r语言绘图·乐备实·labex·科研数据绘图
Jet45058 天前
第100+43步 ChatGPT学习:R语言实现特征选择曲线图
学习·chatgpt·r语言