r 中的 scale-ag捕鱼王app官网

r 中的 scale_y_continuous 函数

作者:迹忆客 最近更新:2023/03/21 浏览次数:

本文将介绍 r 中的 scale_y_continuous 函数。

使用 scale_y_continuous 将 y 轴标签打印为 r 中的百分比

scale_y_continuous 用于设置连续 y 轴比例美学的值。该函数是 ggplot2 包的一部分,它主要与 ggplot 对象一起使用来修改要绘制的图形的不同参数。此示例演示如何使用 scale_y_continuous 将 y 轴标签打印为百分比值。请注意,堆叠条形图是使用 geom_col(position = "fill") 函数调用创建的,百分比是使用 scales::percent 函数作为 labels 参数值打印的。由于我们使用 library 调用包含了 scales 包,因此可以在此脚本的范围内使用 percent 表示法引用它。

library(ggplot2)
library(gridextra)
library(scales)
p1 <- ggplot(orchardsprays, aes(x = rowpos, y = decrease, fill = treatment)) 
  geom_col(position = "fill")
p2 <- ggplot(orchardsprays, aes(x = rowpos, y = decrease, fill = treatment)) 
  geom_col(position = "fill") 
  scale_y_continuous(labels = percent)
grid.arrange(p1, p2, ncol = 2, nrow =2)

r 1 中的 scale_y_continuous

使用 scale_y_continuous 设置 r 中 y 轴的缩放比例

还可以利用 scale_y_continuous 设置 y 轴比例和增量值以打印下一个标签。seq 函数用于将数字序列传递给 scale_y_continuous 调用中的 breaks 参数。它将数字解释为 seq(from, to, by= ) 表示。

library(ggplot2)
library(gridextra)
library(scales)
p1 <- ggplot(orchardsprays, aes(x = rowpos, y = decrease, fill = treatment)) 
  geom_col(position = "fill")
p2 <- ggplot(orchardsprays, aes(x = rowpos, y = decrease, fill = treatment)) 
  geom_col(position = "fill") 
  scale_y_continuous(labels = percent)
p3 <- ggplot(orchardsprays, aes(x = treatment, y = decrease)) 
  geom_point(colour = "blue")
p4 <- ggplot(orchardsprays, aes(x = treatment, y = decrease)) 
  geom_point(colour = "brown") 
  scale_y_continuous(breaks = seq(0, 150, 10))
grid.arrange(p1, p2, p3, p4, ncol = 2, nrow =2)

r 2 中的 scale_y_continuous

使用 scale_y_continuous 删除 r 中 y 轴上的标签

或者,我们可以使用 scale_y_continuous 函数完全删除 y 轴上的标签。为此,我们需要将 null 值作为 breaks 参数传递。请注意,我们绘制了两个图形与 grid.arrange 函数进行视觉比较。

library(ggplot2)
library(gridextra)
p3 <- ggplot(orchardsprays, aes(x = treatment, y = decrease)) 
  geom_boxplot(fill = "cyan")
p4 <- ggplot(orchardsprays, aes(x = treatment, y = decrease)) 
  geom_boxplot(fill = "pink") 
  scale_y_continuous(breaks = null)
grid.arrange(p3, p4, ncol = 2, nrow =2)

r 3 中的 scale_y_continuous

在 r 中使用 scale_y_continuous 使用自定义值修改 y 轴标签

可以混合之前的一些方法以形成更高级的 y 轴美学格式。在以下代码片段中,我们明确指定要打印的多个标签,并同时使用 labels 参数为它们定义新值。请注意,新值只是相应数字的十六进制数字符号。最后,我们使用给定的字符串和 x 轴重命名 y 轴比例,这是使用 scale_x_discrete 函数完成的。

library(ggplot2)
library(gridextra)
p3 <- ggplot(orchardsprays, aes(x = treatment, y = decrease)) 
  geom_boxplot(fill = "cyan")
p4 <- ggplot(orchardsprays, aes(x = treatment, y = decrease)) 
  geom_boxplot(fill = "pink") 
  scale_y_continuous(
    breaks = c(50, 60, 70, 80, 90, 100, 110),
    labels = c("32", "3c", "46", "50", "5a", "64", "6e"),
    name = "decrease\n(hex)") 
  scale_x_discrete(name = "treatment")
grid.arrange(p3, p4, ncol = 2, nrow =2)

r 4 中的 scale_y_continuous

转载请发邮件至 1244347461@qq.com 进行申请,经作者同意之后,转载请以链接形式注明出处

本文地址:

相关文章

发布时间:2024/02/05 浏览次数:207 分类:编程语言

本文介绍了如何交互式清除 r 控制台。

发布时间:2024/02/05 浏览次数:160 分类:编程语言

本文介绍如何用键盘或鼠标停止运行r代码。

发布时间:2024/02/05 浏览次数:223 分类:编程语言

本教程演示了如何设置 r 便携版。

发布时间:2023/03/21 浏览次数:72 分类:编程语言

一项常见的数据分析任务是根据同一行的其他列使用一个或多个条件创建或更新数据框列。 如果我们尝试使用 if 语句来执行此操作,则只会使用第一行来测试条件,并且会根据该行更

发布时间:2023/03/21 浏览次数:198 分类:编程语言

在这篇文章中,你将会了解到两个在 r 中读取 xlsx 文件的最完整和最容易使用的库:readxl 和 openxlsx。

发布时间:2023/03/21 浏览次数:371 分类:编程语言

在本教程中,你将学习如何在 r 中编写一个函数,在不需要重新启动 r 的情况下清除环境。

发布时间:2023/03/21 浏览次数:164 分类:编程语言

本教程演示了如何检查 r 的版本。

发布时间:2023/03/21 浏览次数:222 分类:编程语言

本教程演示了如何在 r 中创建一个空向量。

发布时间:2023/03/21 浏览次数:176 分类:编程语言

本教程演示了如何在 r 向量中查找元素的索引。

扫一扫阅读全部技术教程

社交账号
  • https://www.github.com/onmpw
  • qq:1244347461

最新推荐

教程更新

热门标签

扫码一下
查看教程更方便
网站地图