Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R ggplot2:设置其他特定轴标记_R_Ggplot2 - Fatal编程技术网

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

df
ggplot2
对非变换轴使用基本函数
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所说的附加,我的意思是“替换”,如果已经有标签,则添加,如果没有。因此,第二种选择就可以了。(本可以说得更清楚!)谢谢!如果已经有标签,我的意思是“替换”,如果没有,则是“添加”。因此,第二种选择就可以了。(本可以说得更清楚!)谢谢!