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()
相关推荐
Expecto016 小时前
因子分析——数学原理及R语言代码
算法·r语言·统计学·多元统计分析
人类群星闪耀时19 小时前
R语言数据挖掘:从“挖井”到“淘金”
开发语言·数据挖掘·r语言
Jet45053 天前
第100+40步 ChatGPT学习:R语言实现多轮建模
学习·chatgpt·r语言·多轮建模
Tiger Z3 天前
R 语言科研绘图第 45 期 --- 桑基图-和弦
开发语言·r语言·贴图
敢敢のwings3 天前
论文速读《Embodied-R: 基于强化学习激活预训练模型具身空间推理能力》
开发语言·r语言
清同趣科研4 天前
R绘图|3分钟复现瑞士“苏黎世大学”Nature全球地图——基于R包ggplot2+sf等
开发语言·r语言
就是一顿骚操作7 天前
Linux 部署以paddle Serving 的方式部署 PaddleOCR CPU版本
linux·r语言·paddle
没有梦想的咸鱼185-1037-16638 天前
【大模型ChatGPT+R-Meta】AI赋能R-Meta分析核心技术:从热点挖掘到高级模型、助力高效科研与论文发表“
人工智能·随机森林·机器学习·chatgpt·数据分析·r语言
zhanghongyi_cpp8 天前
R语言操作n
r语言
没有梦想的咸鱼185-1037-16639 天前
回归分析丨基于R语言复杂数据回归与混合效应模型【多水平/分层/嵌套】技术与代码
数据挖掘·数据分析·回归·r语言