R 如何将比例y连续(标签=比例::百分比)更改为

R 如何将比例y连续(标签=比例::百分比)更改为,r,ggplot2,R,Ggplot2,下面是我用一个小样本数据制作的两张图 正如您所看到的,一个子集上升到6%,另一个子集上升到2%,在我的原始数据中,Y比例上升到13%和3.5%,因为我想并排显示它们以显示更大的差异,所以我希望两者的比例都是13%,但我如何更改比例为Y连续(标签=比例::百分比) 我尝试使用的一个例子是下面这个例子,但给了我非常不同的尺度 连续刻度(断开=顺序(0),极限=c(0,6),断开刻度=刻度::百分比) 这是数据样本 Subset_1 <- structure(list(Year.Publishe

下面是我用一个小样本数据制作的两张图

正如您所看到的,一个子集上升到6%,另一个子集上升到2%,在我的原始数据中,Y比例上升到13%和3.5%,因为我想并排显示它们以显示更大的差异,所以我希望两者的比例都是13%,但我如何更改比例为Y连续(标签=比例::百分比)

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

连续刻度(断开=顺序(0),极限=c(0,6),断开刻度=刻度::百分比)

这是数据样本

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))


我相信这就是你想要的:

库(tidyverse)
子集_1%>%
ggplot(不良事件(x=年份已发表,y=频次,组=组))+
geom_线()+
几何点(aes(形状=组))+
比例x连续(中断=最小值(子集1$Year.Published):最大值(子集1$Year.Published))+
连续刻度(断开=顺序(0.13.01),
标签=比例::百分比,
极限=c(0.13))+
比例\u形状\u手册(值=1:n级别(子集\u 1$组))+
主题(legend.title=element_blank())+xlab(‘出版1年的子集’)+ylab(‘出版(%)’)+
主题(axis.text.x=元素\文本(角度=90,hjust=1))


#相对百分比
子集_2%>%
ggplot(不良事件(x=年份已发表,y=频次,组=组))+
geom_线()+
几何点(aes(形状=组))+
比例x连续(中断=最小值(子集2$Year.Published):最大值(子集2$Year.Published))+
连续刻度(断开=顺序(0.13.01),
标签=比例::百分比,
极限=c(0.13))+
比例\u形状\u手册(值=1:n级别(子集\u 2$组))+
主题(legend.title=element_blank())+xlab(‘出版2年的子集’)+ylab(‘出版(%)’)+
主题(axis.text.x=元素\文本(角度=90,hjust=1))


由(v0.2.1)

于2019-02-24创建,使用小数点非常有意义!谢谢是的这正是我想要的!
# 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))