R语言 如何调整离散刻度限制和间隔

r3i60tvu  于 2023-09-27  发布在  其他
关注(0)|答案(1)|浏览(139)

我希望下图中的Y轴从0到100,间隔为10。
我已经尝试了各种方法来做到这一点,但(ylim,scale_y_continuous等),但不断得到错误消息。

library(ggplot2)
library(dplyr)
library(readr)
library(janitor)
library(RColorBrewer)
library(forcats)

#Create data frame
df <- data.frame(Year = c("2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020", "2021", "2022"),
                         ExpeditedDrugsProportion = c(51, 48, 66, 60, 73, 61, 73, 60, 68, 74, 65)
)

df$ExpeditedDrugsProportion <- as.factor(df$ExpeditedDrugsProportion)

#Create plot, labels etc.
ExpeditedApprovals_graph <- ggplot(df, aes(x = Year, y = ExpeditedDrugsProportion)) + 
  geom_point() +
  labs(title = "",
       x = "Year",
       y = "Proportion of newly approved drugs expedited (%)") +
  theme_classic(base_size = 20) 

  
ExpeditedApprovals_graph
kokeuurv

kokeuurv1#

不要将x轴变量转换为因子,它适用于scale_y_continuous

library(ggplot2)
library(dplyr)
library(readr)
library(janitor)
library(RColorBrewer)
library(forcats)

#Create data frame
df <- data.frame(Year = c("2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020", "2021", "2022"),
                 ExpeditedDrugsProportion = c(51, 48, 66, 60, 73, 61, 73, 60, 68, 74, 65)
)

#Create plot, labels etc.
ExpeditedApprovals_graph <- ggplot(df, aes(x = Year, y = ExpeditedDrugsProportion)) + 
  geom_point() +
  labs(title = "",
       x = "Year",
       y = "Proportion of newly approved drugs expedited (%)") +
  theme_classic(base_size = 20) +
  scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, by = 10))

ExpeditedApprovals_graph

相关问题