在下面的示例中,如何將 x 標簽四舍五入為偶數?我不能先將它們轉換為因子,因為geom_smooth那樣不起作用
library(ggplot2)
set.seed(32)
df <- data.frame(a = as.integer(rnorm(250, 2, 0.1)))
df$b <- df$a rnorm(250)
df$id = 1
df_2 <- df
df_2$id <- 2
df_tot <- rbind(df, df_2)
ggplot(df_tot, aes(x = a, y = b))
geom_smooth()
facet_wrap(~id)
uj5u.com熱心網友回復:
如果我們想要偶數,一個選項是添加labels為函式scale_x_continuous
library(ggplot2)
ggplot(df_tot, aes(x = a, y = b))
geom_smooth()
facet_wrap(~id)
scale_x_continuous(labels = function(x) seq(2, length.out = length(x)))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/462747.html
