R包:‘ggcharts好看线图包‘

介绍

ggcharts提供了一个高级{ggplot2}接口,用于创建通用图表。它的目标既简单又雄心勃勃:让您更快地从数据可视化的想法到实际的绘图。所以如何?通过处理大量的数据预处理,为您模糊{ggplot2}细节和绘图样式。生成的图是ggplot对象,可以使用任何{ggplot2}函数进一步定制。

remotes::install_github("thomas-neitmann/ggcharts")
library(ggcharts)
library(tidyverse)
data("biomedicalrevenue")

pl1 <- biomedicalrevenue %>%
  filter(year %in% c(2012, 2015, 2018)) %>%
  group_by(year) %>%
  top_n(10, revenue) %>%
  ungroup() %>%
  mutate(company = tidytext::reorder_within(company, revenue, year)) %>%
  ggplot(aes(company, revenue)) +
  geom_col() +
  coord_flip() +
  tidytext::scale_x_reordered() +
  facet_wrap(vars(year), scales = "free_y")

pl2 <- biomedicalrevenue %>%
  filter(year %in% c(2012, 2015, 2018)) %>%
  bar_chart(x = company, y = revenue, facet = year, top_n = 10)

wrap_plots(pl1, pl2, ncol = 1)

在这里插入图片描述

Charts

各种线图

data("revenue_wide")

line_chart(data = revenue_wide, x = year, y = Roche:Bayer) +
  labs(x = "Year", y = "Revenue (Billion USD)")

在这里插入图片描述

biomedicalrevenue %>%
  filter(year == 2018) %>%
  lollipop_chart(x = company, y = revenue, threshold = 30) +
  labs(
    x = NULL,
    y = "Revenue",
    title = "Biomedical Companies with Revenue > $30Bn."
  ) +
  scale_y_continuous(
    labels = function(x) paste0("$", x, "Bn."),
    expand = expansion(mult = c(0, .05))
  )

在这里插入图片描述

data("popeurope")
dumbbell_chart(
  data = popeurope,
  x = country,
  y1 = pop1952,
  y2 = pop2007,
  top_n = 10,
  point_colors = c("lightgray", "#494F5C")
) +
  labs(
    x = NULL,
    y = "Population",
    title = "Europe's Largest Countries by Population in 2007"
  ) +
  scale_y_continuous(
    limits = c(0, NA),
    labels = function(x) paste(x, "Mn.")
  )

在这里插入图片描述

data(mtcars)
mtcars_z <- dplyr::transmute(
  .data = mtcars,
  model = row.names(mtcars),
  hpz = scale(hp)
)

diverging_bar_chart(data = mtcars_z, x = model, y = hpz)

在这里插入图片描述

diverging_lollipop_chart(
  data = mtcars_z,
  x = model,
  y = hpz,
  lollipop_colors = c("#006400", "#b32134"),
  text_color = c("#006400", "#b32134")
)

在这里插入图片描述

data("popch")
pyramid_chart(data = popch, x = age, y = pop, group = sex)

在这里插入图片描述

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 10:40:02       101 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 10:40:02       108 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 10:40:02       91 阅读
  4. Python语言-面向对象

    2024-07-11 10:40:02       98 阅读

热门阅读

  1. 人工智能在自动驾驶中的目标检测研究

    2024-07-11 10:40:02       28 阅读
  2. 编程语言 Public:深度解析与未来展望

    2024-07-11 10:40:02       29 阅读
  3. 【SQL】InnoDB中的行锁

    2024-07-11 10:40:02       30 阅读
  4. 编程什么好用:深入剖析编程工具的选择与运用

    2024-07-11 10:40:02       27 阅读
  5. C++引用和指针的区别

    2024-07-11 10:40:02       24 阅读
  6. 3.数组基础

    2024-07-11 10:40:02       21 阅读
  7. Docker 日志丢失 - 解决方案

    2024-07-11 10:40:02       23 阅读
  8. 3D Web开发新篇章:threelab探索之旅

    2024-07-11 10:40:02       22 阅读
  9. 外科休克病人的护理

    2024-07-11 10:40:02       26 阅读