ggplot 区域外部(右侧)的 ggrepel 标签

2023-12-02

library(tidyverse)
library(ggrepel)
df <- structure(list(Fruit = c("Yellow Pear", "Yellow Pear", "Yellow Pear", 
"Yellow Pear", "Yellow Pear", "Yellow Pear", "Yellow Pear", "Yellow Pear", 
"Yellow Pear", "Yellow Pear", "Yellow Pear", "Yellow Pear", "Tropical Banana", 
"Tropical Banana", "Tropical Banana", "Tropical Banana", "Tropical Banana", 
"Tropical Banana", "Tropical Banana", "Tropical Banana", "Tropical Banana", 
"Tropical Banana", "Tropical Banana", "Tropical Banana", "Farm Fresh Strawberries", 
"Farm Fresh Strawberries", "Farm Fresh Strawberries", "Farm Fresh Strawberries", 
"Farm Fresh Strawberries", "Farm Fresh Strawberries", "Farm Fresh Strawberries", 
"Farm Fresh Strawberries", "Farm Fresh Strawberries", "Farm Fresh Strawberries", 
"Farm Fresh Strawberries", "Farm Fresh Strawberries", "Melon Mango", 
"Melon Mango", "Melon Mango", "Melon Mango", "Melon Mango", "Melon Mango", 
"Melon Mango", "Melon Mango", "Melon Mango", "Melon Mango", "Melon Mango", 
"Melon Mango", "Dragonfruit", "Dragonfruit", "Dragonfruit", "Dragonfruit", 
"Dragonfruit", "Dragonfruit", "Dragonfruit", "Dragonfruit", "Dragonfruit", 
"Dragonfruit", "Dragonfruit", "Dragonfruit", "Peaches", "Peaches", 
"Peaches", "Peaches", "Peaches", "Peaches", "Peaches", "Peaches", 
"Peaches", "Peaches", "Peaches", "Peaches", "Blueberry", "Blueberry", 
"Blueberry", "Blueberry", "Blueberry", "Blueberry", "Blueberry", 
"Blueberry", "Blueberry", "Blueberry", "Blueberry", "Blueberry", 
"Blueberry GS", "Blueberry GS", "Blueberry GS", "Blueberry GS", 
"Blueberry GS", "Blueberry GS", "Blueberry GS", "Blueberry GS", 
"Blueberry GS", "Blueberry GS", "Blueberry GS", "Blueberry GS", 
"Red Delicious Apples", "Red Delicious Apples", "Red Delicious Apples", 
"Red Delicious Apples", "Red Delicious Apples", "Red Delicious Apples", 
"Red Delicious Apples", "Red Delicious Apples", "Red Delicious Apples", 
"Red Delicious Apples", "Red Delicious Apples", "Red Delicious Apples", 
"Grapes", "Grapes", "Grapes", "Grapes", "Grapes", "Grapes", "Grapes", 
"Grapes", "Grapes", "Grapes", "Grapes", "Grapes", "Cherry", "Cherry", 
"Cherry", "Cherry", "Cherry", "Cherry", "Cherry", "Cherry", "Cherry", 
"Cherry", "Cherry", "Cherry", "Green Apples", "Green Apples", 
"Green Apples", "Green Apples", "Green Apples", "Green Apples", 
"Green Apples", "Green Apples", "Green Apples", "Green Apples", 
"Green Apples", "Green Apples", "Yellow Apples", "Yellow Apples", 
"Yellow Apples", "Yellow Apples", "Yellow Apples", "Yellow Apples", 
"Yellow Apples", "Yellow Apples", "Yellow Apples", "Yellow Apples", 
"Yellow Apples", "Yellow Apples", "Perfect Punchy Pineapple", 
"Perfect Punchy Pineapple", "Perfect Punchy Pineapple", "Perfect Punchy Pineapple", 
"Perfect Punchy Pineapple", "Perfect Punchy Pineapple", "Perfect Punchy Pineapple", 
"Perfect Punchy Pineapple", "Perfect Punchy Pineapple", "Perfect Punchy Pineapple", 
"Perfect Punchy Pineapple", "Perfect Punchy Pineapple", "Watermelon", 
"Watermelon", "Watermelon", "Watermelon", "Watermelon", "Watermelon", 
"Watermelon", "Watermelon", "Watermelon", "Watermelon", "Watermelon", 
"Watermelon", "Red Raspberry", "Red Raspberry", "Red Raspberry", 
"Red Raspberry", "Red Raspberry", "Red Raspberry", "Red Raspberry", 
"Red Raspberry", "Red Raspberry", "Red Raspberry", "Red Raspberry", 
"Red Raspberry", "Blackberry", "Blackberry", "Blackberry", "Blackberry", 
"Blackberry", "Blackberry", "Blackberry", "Blackberry", "Blackberry", 
"Blackberry", "Blackberry", "Blackberry", "Avocado", "Avocado", 
"Avocado", "Avocado", "Avocado", "Avocado", "Avocado", "Avocado", 
"Avocado", "Avocado", "Avocado", "Avocado", "Cherimoya Custard Apple", 
"Cherimoya Custard Apple", "Cherimoya Custard Apple", "Cherimoya Custard Apple", 
"Cherimoya Custard Apple", "Cherimoya Custard Apple", "Cherimoya Custard Apple", 
"Cherimoya Custard Apple", "Cherimoya Custard Apple", "Cherimoya Custard Apple", 
"Cherimoya Custard Apple", "Cherimoya Custard Apple", "Nectarine", 
"Nectarine", "Nectarine", "Nectarine", "Nectarine", "Nectarine", 
"Nectarine", "Nectarine", "Nectarine", "Nectarine", "Nectarine", 
"Nectarine", "Plum Prune Pineapple", "Plum Prune Pineapple", 
"Plum Prune Pineapple", "Plum Prune Pineapple", "Plum Prune Pineapple", 
"Plum Prune Pineapple", "Plum Prune Pineapple", "Plum Prune Pineapple", 
"Plum Prune Pineapple", "Plum Prune Pineapple", "Plum Prune Pineapple", 
"Plum Prune Pineapple", "Pomegranate", "Pomegranate", "Pomegranate", 
"Pomegranate", "Pomegranate", "Pomegranate", "Pomegranate", "Pomegranate", 
"Pomegranate", "Pomegranate", "Pomegranate", "Pomegranate", "Surinam Cherry", 
"Surinam Cherry", "Surinam Cherry", "Surinam Cherry", "Surinam Cherry", 
"Surinam Cherry", "Surinam Cherry", "Surinam Cherry", "Surinam Cherry", 
"Surinam Cherry", "Surinam Cherry", "Surinam Cherry"), Date = structure(c(17622, 
17652, 17683, 17713, 17744, 17775, 17805, 17836, 17866, 17897, 
17928, 17956, 17622, 17652, 17683, 17713, 17744, 17775, 17805, 
17836, 17866, 17897, 17928, 17956, 17622, 17652, 17683, 17713, 
17744, 17775, 17805, 17836, 17866, 17897, 17928, 17956, 17622, 
17652, 17683, 17713, 17744, 17775, 17805, 17836, 17866, 17897, 
17928, 17956, 17622, 17652, 17683, 17713, 17744, 17775, 17805, 
17836, 17866, 17897, 17928, 17956, 17622, 17652, 17683, 17713, 
17744, 17775, 17805, 17836, 17866, 17897, 17928, 17956, 17622, 
17652, 17683, 17713, 17744, 17775, 17805, 17836, 17866, 17897, 
17928, 17956, 17622, 17652, 17683, 17713, 17744, 17775, 17805, 
17836, 17866, 17897, 17928, 17956, 17622, 17652, 17683, 17713, 
17744, 17775, 17805, 17836, 17866, 17897, 17928, 17956, 17622, 
17652, 17683, 17713, 17744, 17775, 17805, 17836, 17866, 17897, 
17928, 17956, 17622, 17652, 17683, 17713, 17744, 17775, 17805, 
17836, 17866, 17897, 17928, 17956, 17622, 17652, 17683, 17713, 
17744, 17775, 17805, 17836, 17866, 17897, 17928, 17956, 17622, 
17652, 17683, 17713, 17744, 17775, 17805, 17836, 17866, 17897, 
17928, 17956, 17622, 17652, 17683, 17713, 17744, 17775, 17805, 
17836, 17866, 17897, 17928, 17956, 17622, 17652, 17683, 17713, 
17744, 17775, 17805, 17836, 17866, 17897, 17928, 17956, 17622, 
17652, 17683, 17713, 17744, 17775, 17805, 17836, 17866, 17897, 
17928, 17956, 17622, 17652, 17683, 17713, 17744, 17775, 17805, 
17836, 17866, 17897, 17928, 17956, 17622, 17652, 17683, 17713, 
17744, 17775, 17805, 17836, 17866, 17897, 17928, 17956, 17622, 
17652, 17683, 17713, 17744, 17775, 17805, 17836, 17866, 17897, 
17928, 17956, 17622, 17652, 17683, 17713, 17744, 17775, 17805, 
17836, 17866, 17897, 17928, 17956, 17622, 17652, 17683, 17713, 
17744, 17775, 17805, 17836, 17866, 17897, 17928, 17956, 17622, 
17652, 17683, 17713, 17744, 17775, 17805, 17836, 17866, 17897, 
17928, 17956, 17622, 17652, 17683, 17713, 17744, 17775, 17805, 
17836, 17866, 17897, 17928, 17956), class = "Date"), Value = c(0.00488, 
0.00603, 0.00477, 0.00589, 0.00814, 0.00642, 0.00679, 0.00609, 
0.00403, 0.00909, 0.00727, 0.0048, 0.02366, 0.01599, 0.01527, 
0.0164, 0.01521, 0.01566, 0.01381, 0.01941, 0.0196, 0.02411, 
0.02158, 0.02307, 0.02161, 0.02419, 0.02393, 0.01991, 0.0218, 
0.02036, 0.01666, 0.02389, 0.01842, 0.02932, 0.01998, 0.02315, 
0.04053, 0.04161, 0.04045, 0.04937, 0.03595, 0.03852, 0.04895, 
0.03786, 0.03136, 0.04497, 0.03678, 0.04276, 0.00175, 0.00243, 
0.00474, 0.00502, 0.00665, 0.00457, 0.00847, 0.00494, 0.00271, 
0.00265, 0.00602, 0.00451, 0.03749, 0.0341, 0.03823, 0.0432, 
0.04814, 0.03773, 0.03829, 0.0383, 0.03803, 0.04674, 0.03968, 
0.04482, 0.25824, 0.2541, 0.26486, 0.32075, 0.26146, 0.27273, 
0.28191, 0.23684, 0.22193, 0.29765, 0.30052, 0.31282, 0.0131, 
0.02674, 0.01137, 0.01965, 0.02185, 0.02844, 0.02298, 0.02145, 
0.02187, 0.03242, 0.02213, 0.02128, 0.05535, 0.0588, 0.05653, 
0.05804, 0.04997, 0.05085, 0.05835, 0.05721, 0.05204, 0.06247, 
0.06009, 0.06425, 0.275, 0.5, 0.4, 0.375, 0.45, 0.425, 0.275, 
0.275, 0.225, 0.3, 0.325, 0.35, 0.25047, 0.26969, 0.23524, 0.21364, 
0.23965, 0.21167, 0.2466, 0.2575, 0.22213, 0.23955, 0.22099, 
0.20157, 0.01455, 0.01958, 0.0194, 0.01931, 0.01916, 0.01901, 
0.02117, 0.02436, 0.03012, 0.02367, 0.0211, 0.01618, 0.03707, 
0.03481, 0.03357, 0.03637, 0.04391, 0.03939, 0.03922, 0.05372, 
0.03559, 0.05253, 0.04771, 0.04948, 0.09733, 0.12215, 0.11575, 
0.10066, 0.11662, 0.09571, 0.09593, 0.11425, 0.09891, 0.13107, 
0.11913, 0.12753, 0.16986, 0.17615, 0.21867, 0.18883, 0.18898, 
0.22762, 0.135, 0.17317, 0.16945, 0.14858, 0.19451, 0.11659, 
0.09441, 0.15135, 0.11804, 0.11181, 0.12594, 0.10972, 0.11313, 
0.08373, 0.10206, 0.10558, 0.08821, 0.10629, 0.01472, 0.01466, 
0.01521, 0.01733, 0.01718, 0.01489, 0.01457, 0.0174, 0.01009, 
0.01713, 0.01636, 0.01198, 0.0687, 0.08581, 0.08247, 0.08407, 
0.08265, 0.0785, 0.06906, 0.08113, 0.07246, 0.07717, 0.07311, 
0.07862, 0.04762, 0.02301, 0.01534, 0.0291, 0.03063, 0.02757, 
0.0229, 0.03049, 0.01524, 0.01524, 0.01979, 0.02435, 0.3038, 
0.32317, 0.34615, 0.28571, 0.30423, 0.35196, 0.34341, 0.28165, 
0.24615, 0.26303, 0.3, 0.28471, 0.20833, 0.21667, 0.28926, 0.29032, 
0.31496, 0.18182, 0.31343, 0.26277, 0.23188, 0.26056, 0.24658, 
0.21711, 0.24265, 0.38571, 0.22667, 0.24837, 0.29221, 0.27848, 
0.2622, 0.28824, 0.26901, 0.29444, 0.2459, 0.3, 0.25843, 0.2809, 
0.18436, 0.3352, 0.26816, 0.22222, 0.25556, 0.24309, 0.22099, 
0.24309, 0.21547, 0.20879), Violation = c(FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
-276L)) %>% 
  mutate(label = if_else(Date == max(Date), Fruit, NA_character_))

df
#> # A tibble: 276 x 5
#>    Fruit       Date         Value Violation label
#>    <chr>       <date>       <dbl> <lgl>     <chr>
#>  1 Yellow Pear 2018-04-01 0.00488 FALSE     NA   
#>  2 Yellow Pear 2018-05-01 0.00603 FALSE     NA   
#>  3 Yellow Pear 2018-06-01 0.00477 FALSE     NA   
#>  4 Yellow Pear 2018-07-01 0.00589 FALSE     NA   
#>  5 Yellow Pear 2018-08-01 0.00814 FALSE     NA   
#>  6 Yellow Pear 2018-09-01 0.00642 FALSE     NA   
#>  7 Yellow Pear 2018-10-01 0.00679 FALSE     NA   
#>  8 Yellow Pear 2018-11-01 0.00609 FALSE     NA   
#>  9 Yellow Pear 2018-12-01 0.00403 FALSE     NA   
#> 10 Yellow Pear 2019-01-01 0.00909 FALSE     NA   
#> # ... with 266 more rows

对于上面巨大的数据框代码块感到抱歉。这就是我正在处理的事情。请将其复制粘贴到 R Studio 中以开始使用。

现在已经完成了,我正在努力获得ggrepel包装上标注红线如下图所示。我一直在旋转旋钮(参数)ggrepel但无法得到任何漂亮的东西。我希望标签不碍事,并以与线条排列顺序相同的顺序到达图表的右侧。我们可以将标签也设为红色吗?

What ggrepel争论会让我到达那里吗?或者有没有更好的方法可以用普通的 ggplot 来做到这一点?

ggplot(df, aes(Date, Value, group = Fruit)) + 
  geom_line(aes(color = Violation)) +
  scale_color_manual(values = c("grey30", "red")) + 
  scale_x_date(breaks = "month", date_labels = "%b") +
  scale_y_continuous(breaks = seq(0, 0.7, by = 0.05)) + 
  coord_cartesian(ylim = c(-0.25, 0.7)) +
  labs(x = NULL, y = "Value\n") +
  theme_minimal() + 
  theme(panel.grid = element_blank(),
        axis.ticks.x = element_line(),
        #axis.line.x = element_blank(),
        axis.line.y = element_line(), 
        axis.ticks.y = element_line()) + 
  geom_text_repel(data = df %>% filter(Violation == TRUE),
                  aes(label = label), 
                  direction = "y", 
                  hjust = 0, 
                  segment.size = 0.2,
                  nudge_x = 1,
                  na.rm = TRUE)

ggrepel labels


ggplot(df, aes(Date, Value, group = Fruit)) + 
  geom_line(aes(color = Violation)) +
  scale_color_manual(values = c("grey30", "red")) + 
  scale_x_date(breaks = "month", date_labels = "%b") +
  scale_y_continuous(breaks = seq(0, 0.7, by = 0.05)) + 
  coord_cartesian(ylim = c(-0.25, 0.7), clip = "off") +
  labs(x = NULL, y = "Value\n") +
  theme_minimal() + 
  theme(panel.grid = element_blank(),
        axis.ticks.x = element_line(),
        #axis.line.x = element_blank(),
        axis.line.y = element_line(), 
        axis.ticks.y = element_line(), 
        legend.position = c(0.8, 0.8),
        plot.margin = unit(c(0.1, 5, 0.1, 0.1), "cm")) + 
  geom_text_repel(data = df %>% filter(Violation == TRUE),
                  aes(label = label), 
                  direction = "y", 
                  hjust = 0, 
                  segment.size = 0.2,
                  na.rm = TRUE,
                  xlim = as.Date(c("2019-04-01", "2019-10-01")),
                  ylim = c(0, .2))

enter image description here

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ggplot 区域外部(右侧)的 ggrepel 标签 的相关文章

  • 根据 R 中的另一个变量过滤簇中的 id

    我有 100 名患者的数据 每个患者都有 7 天 1 到 7 的值 如何仅在第一天根据另一个变量选择患者 df lt data frame id c 1 1 1 2 2 2 day c 1 2 3 1 2 3 RRT c 0 1 0 1 0
  • 在r中水平旋转直方图

    谁能帮我如何在 r 中将直方图旋转 90 度 我知道箱线图中有一个选项 horiz T 但我不知道直方图是否有类似的选项 我认为你必须使用 hist 和 barplot 来完成它 如下所示 直接来自文档 你可以在这里检查它 layout x
  • 将时间值转换为数字,同时保留时间特征

    我有一个数据集 其中包含不同事件发生的间隔时间 我想要做的是将数据转换为数字向量 以便更容易操作和运行摘要 制作图表等 同时保持其时间特征 这是我的数据片段 data lt c 03 31 12 17 16 29 09 52 04 01 0
  • 将值排列在特定组内

    我试图在嵌套数据帧的精确组内按降序排列值 我的输入数据如下所示 我有两个分组变量 group1 and group2 和三个值 即id value2 value3 library tidyverse set seed 1234 df lt
  • 如何从 Matlab 运行 R 脚本 [重复]

    这个问题在这里已经有答案了 我有 m 文件 我想用它来运行 R 脚本 我怎样才能做到这一点 Matlab文件 caller m some matlab code need to call a R script some matlab cod
  • r - ggplot2 - 突出显示选定的点和奇怪的行为

    我想突出显示选定的点并遇到一些奇怪的行为 首先是一些虚拟数据 a lt 1 50 b lt rnorm 50 mydata lt data frame a a b b ggplot mydata aes x a y b geom point
  • R 连接到主机时出错

    我已经安装了 R 3 0 2 和包KEGGREST 在使用它的命令时 我收到以下错误 函数错误 类型 消息 asError TRUE 无法连接到 主持人 使用 internet2 选项后 我可以很好地从互联网安装软件包 该选项使用来自 In
  • 在 jupyter 笔记本中内联显示 R ggplots

    我正在尝试运行这里找到的一个简单示例 https www datacamp com community blog jupyter notebook r gs OczVCjA https www datacamp com community
  • 如何根据一个值过滤远程表?

    我正在做一个filter using in 但 dplyr 翻译查询的方式似乎不正确 事实上 in 运算符对于多个值可以正常工作 但当仅存在单个元素时则不行 在我最初的场景中 过滤值是动态的 因此我希望有一个在这两种情况下都有效的函数 my
  • 如何有条件地选择一列,并从 R 中另一个有条件选择的列中的行中减去这些行中的值?

    我知道我的问题标题很冗长 可能很难理解 所以我会尽力在这里解释一下 这是一些示例数据 transactions lt tibble id seq 1 7 day paste rep day each 7 seq 1 7 sep sent t
  • 将 jupyter R 内核与 Visual Studio 代码结合使用

    对于 python jupyter 笔记本 我目前正在使用 VSCode python 扩展 但是我找不到任何使用替代内核的方法 我对 jupyter R 内核特别感兴趣 有没有办法在 VSCode 中使用 R 内核来处理 jupyter
  • 如何以 HH:MM 表示小数时间

    我有一个十进制格式的时间 22 13以小时为单位 我想在 R 中将其表达为HH MM 我是说 22 08 贬值秒 有人可以帮助我吗 语法 02 0f是将值四舍五入为整数并使其始终为 2 个单位 所以 7 8分钟将转换为字符 08 x lt
  • 使用 dplyr 对 R 中所有因变量进行分组汇总统计

    我正在尝试为 10 个因变量中的每一个生成分组 听力 我的自变量 因此 HL 和 NH 是两个组 汇总统计数据 平均值 标准差 最小值 最大值 标准误差等 我可以使用以下 2 个代码对一个变量 R PTA 执行此操作 1 RightPTA
  • 替换 gtable 中 ggplot 的元素:标签和网格线

    我正在学习操纵ggplot对象与gtable 这是我问的一个相关问题 用 grid 和 gtable 拆解 ggplot https stackoverflow com questions 27750737 dismantling a gg
  • 当隐含 ID 列时,如何合并 csv 文件中的多个数据框?

    我想将一堆数据框合并在一起 因为如果您只处理一个数据框 则许多操作似乎会更容易 但如果我错了 请纠正我 目前我有一个像这样的数据框 ID var1 var2 A 2 2 B 4 5 Z 3 2 每个 ID 位于单行上 并带有多个单个测量值
  • 绘图中的 R 科学记数法

    我有一个简单的情节 usr bin Rscript png plot png y lt c 102 258 2314 x lt c 482563 922167 4462665 plot x y dev off R 使用 500 1000 1
  • merge.zoo 删除时区

    的结果merge zoo与其输入的时区不同 考虑下面的例子 library zoo zoo a zoo data frame a 1 5 seq as POSIXct 2014 01 01 00 00 01 tz UTC as POSIXc
  • 用 R 将矩阵划分为 N 个大小相等的块

    如何使用 R 将矩阵或数据帧划分为 N 个大小相等的块 我想水平切割矩阵或数据框 例如 给定 r 8 c 10 number of chunks 4 data matrix seq r c nrow r ncol c gt gt gt da
  • OpenBUGS:伯努利分布中缺失值

    我正在尝试通过 R R2OpenBUGS 使用 OpenBUGS 将观察 时间 建模为随机变量 如果所有观察时间都可用 没有 NA 则一切正常 但如果我将其中一个时间设置为 NA 则什么也不会发生 我使用 WinBUGS 测试了相同的代码
  • 泛化 R %in% 运算符以匹配元组

    前几天我花了一段时间寻找一种方法来检查行向量是否包含在 R 中的某些行向量集中 基本上 我想概括 in 运算符来匹配元组而不是向量中的每个条目 例如 我想要 row vec c A 3 row vec 1 A 3 data set rbin

随机推荐