以下是我使用少量数据样本制作的2张图graphs
您可以看到一个子集上升了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))
答案 0 :(得分:0)
我相信这是您想要的:
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(v0.2.1)于2019-02-24创建