R ggplot2:设置其他特定轴标记
我有一个情节:R ggplot2:设置其他特定轴标记,r,ggplot2,R,Ggplot2,我有一个情节: ggplot()+geom_line(data = data.frame(y = c(1,2,3), x=c(1,2,3)), aes(y=y,x=x)) 我希望保留默认的轴打断和标签(在我的程序中,我事先不知道绘图的限制。) 在x=1.5时,我想在x轴上添加一个带有标签“hi”的附加记号 我知道scale\u x\u continuous(),但我不知道如何访问“由变换对象计算的默认打断”。ggplot2对非变换轴使用基本函数pretty(通过scales::pretty\
ggplot()+geom_line(data = data.frame(y = c(1,2,3), x=c(1,2,3)), aes(y=y,x=x))
我希望保留默认的轴打断和标签(在我的程序中,我事先不知道绘图的限制。)
在x=1.5时,我想在x轴上添加一个带有标签“hi”的附加记号
我知道
scale\u x\u continuous()
,但我不知道如何访问“由变换对象计算的默认打断”。ggplot2
对非变换轴使用基本函数pretty
(通过scales::pretty\u breaks
间接实现)。利用这个优势:
df <- data.frame(y = c(1,2,3), x=c(1,2,3))
ggplot(df, aes(x, y)) +
geom_line() +
scale_x_continuous(breaks = c(pretty(df$x), 1.5), labels = c(pretty(df$x), 'hi'))
dfggplot2
对非变换轴使用基本函数pretty
(通过scales::pretty_breaks
间接实现)。利用这个优势:
df <- data.frame(y = c(1,2,3), x=c(1,2,3))
ggplot(df, aes(x, y)) +
geom_line() +
scale_x_continuous(breaks = c(pretty(df$x), 1.5), labels = c(pretty(df$x), 'hi'))
df所说的附加,我的意思是“替换”,如果已经有标签,则添加,如果没有。因此,第二种选择就可以了。(本可以说得更清楚!)谢谢!如果已经有标签,我的意思是“替换”,如果没有,则是“添加”。因此,第二种选择就可以了。(本可以说得更清楚!)谢谢!