gpt4 book ai didi

r - 如何将scale_y_continuous(labels = scales::percent) 更改为

转载 作者:行者123 更新时间:2023-12-03 08:56:37 28 4
gpt4 key购买 nike

这是我使用一小部分数据 graphs 制作的 2 个图表

正如你所看到的,一个子集上升到 6%,另一个子集上升到 2%,在我的原始数据上,Y 比例上升到 13% 和 3.5%,因为我想并排显示它们更大的差异我希望两者都具有相同的 13% 比例,但是如何更改scale_y_continuous(labels = scales::percent) 的比例?

我尝试使用的一个例子是下面这个例子,但给了我非常不同的比例

scale_y_continuous(breaks=seq(0),limits=c(0,6),breakslabels = scales::percent)

这是数据示例

Subset_1 <- structure(list(Year.Published = c(1993, 1993, 1993, 1993, 1993, 
1993, 1993, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1995, 1995,
1995, 1995, 1995, 1995, 1995, 1996, 1996, 1996, 1996, 1996, 1996,
1996), group = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L,
5L, 6L, 7L), .Label = c("A1", "A2",
"B", "I", "L", "M", "N"), class = "factor"), numPapers = c(791L, 791L, 791L, 791L, 791L,
791L, 791L, 990L, 990L, 990L, 990L, 990L, 990L, 990L, 1129L,
1129L, 1129L, 1129L, 1129L, 1129L, 1129L, 1012L, 1012L, 1012L,
1012L, 1012L, 1012L, 1012L), numMentions = c(0L, 1L, 17L, 0L,
4L, 22L, 1L, 0L, 3L, 13L, 0L, 8L, 25L, 0L, 0L, 8L, 31L, 0L, 8L,
54L, 7L, 1L, 15L, 35L, 0L, 10L, 60L, 5L), freqMentions = c(0,
0.00126422250316056, 0.0214917825537295, 0, 0.00505689001264223,
0.0278128950695322, 0.00126422250316056, 0, 0.00303030303030303,
0.0131313131313131, 0, 0.00808080808080808, 0.0252525252525253,
0, 0, 0.0070859167404783, 0.0274579273693534, 0, 0.0070859167404783,
0.0478299379982285, 0.00620017714791851, 0.000988142292490119,
0.0148221343873518, 0.0345849802371542, 0, 0.00988142292490119,
0.0592885375494071, 0.00494071146245059)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -28L))

Subset_2 <-structure(list(Year.Published = c(1993, 1993, 1993, 1993, 1993,
1993, 1993, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1995, 1995,
1995, 1995, 1995, 1995, 1995, 1996, 1996, 1996, 1996, 1996, 1996,
1996), group = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L,
5L, 6L, 7L), .Label = c("A1", "A2", "B", "I", "L", "M", "N"), class = "factor"),
numPapers = c(3648L, 3648L, 3648L, 3648L,
3648L, 3648L, 3648L, 4426L, 4426L, 4426L, 4426L, 4426L, 4426L,
4426L, 5019L, 5019L, 5019L, 5019L, 5019L, 5019L, 5019L, 4942L,
4942L, 4942L, 4942L, 4942L, 4942L, 4942L), numMentions = c(0L,
5L, 26L, 0L, 4L, 45L, 3L, 2L, 6L, 27L, 0L, 1L, 50L, 5L, 1L, 13L,
42L, 0L, 14L, 70L, 10L, 0L, 18L, 58L, 0L, 15L, 93L, 8L), freqMentions = c(0,
0.00137061403508772, 0.00712719298245614, 0, 0.00109649122807018,
0.0123355263157895, 0.000822368421052632, 0.000451875282422052,
0.00135562584726615, 0.0061003163126977, 0, 0.000225937641211026,
0.0112968820605513, 0.00112968820605513, 0.000199242877067145,
0.00259015740187288, 0.00836820083682008, 0, 0.00278940027894003,
0.0139470013947001, 0.00199242877067145, 0, 0.00364225010117361,
0.0117361392148928, 0, 0.00303520841764468, 0.018818292189397,
0.00161877782274383)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -28L))
dput(head(RCT_USA_mod,28))

这是我的 Ggplot2 代码

# Relative Percentage
Subset_1 %>%
ggplot(aes(x = Year.Published, y = freqMentions, group = group)) +
geom_line() +
geom_point(aes(shape = group)) +
scale_x_continuous(breaks = min(Subset_1$Year.Published):max(Subset_1$Year.Published)) +
scale_y_continuous(labels = scales::percent) +
scale_shape_manual(values = 1 : nlevels(Subset_1$group)) +
theme(legend.title = element_blank())+ xlab('Subset 1 Year of Publication')+ylab('Publications (%)')+
theme(axis.text.x=element_text(angle=90,hjust=1))


# Relative Percentage
Subset_2 %>%
ggplot(aes(x = Year.Published, y = freqMentions, group = group)) +
geom_line() +
geom_point(aes(shape = group)) +
scale_x_continuous(breaks = min(Subset_2$Year.Published):max(Subset_2$Year.Published)) +
scale_y_continuous(labels = scales::percent) +
scale_shape_manual(values = 1 : nlevels(Subset_2$group)) +
theme(legend.title = element_blank())+ xlab('Subset 2 Year of Publication')+ylab('Publications(%)')+
theme(axis.text.x=element_text(angle=90,hjust=1))

enter image description here

最佳答案

我相信这就是您正在寻找的:

library(tidyverse)

Subset_1 %>%
ggplot(aes(x = Year.Published, y = freqMentions, group = group)) +
geom_line() +
geom_point(aes(shape = group)) +
scale_x_continuous(breaks = min(Subset_1$Year.Published):max(Subset_1$Year.Published)) +
scale_y_continuous(breaks = seq(0, .13, .01),
labels = scales::percent,
limits = c(0, .13)) +
scale_shape_manual(values = 1 : nlevels(Subset_1$group)) +
theme(legend.title = element_blank())+ xlab('Subset 1 Year of Publication')+ylab('Publications (%)')+
theme(axis.text.x=element_text(angle=90,hjust=1))



# Relative Percentage
Subset_2 %>%
ggplot(aes(x = Year.Published, y = freqMentions, group = group)) +
geom_line() +
geom_point(aes(shape = group)) +
scale_x_continuous(breaks = min(Subset_2$Year.Published):max(Subset_2$Year.Published)) +
scale_y_continuous(breaks = seq(0, .13, .01),
labels = scales::percent,
limits = c(0, .13)) +
scale_shape_manual(values = 1 : nlevels(Subset_2$group)) +
theme(legend.title = element_blank())+ xlab('Subset 2 Year of Publication')+ylab('Publications(%)')+
theme(axis.text.x=element_text(angle=90,hjust=1))

reprex package 于 2019-02-24 创建(v0.2.1)

关于r - 如何将scale_y_continuous(labels = scales::percent) 更改为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54858650/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com