Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.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 如何在geom_文本中给出多个条件_R_Data Visualization_Geom Text - Fatal编程技术网

R 如何在geom_文本中给出多个条件

R 如何在geom_文本中给出多个条件,r,data-visualization,geom-text,R,Data Visualization,Geom Text,我有一个股票价格随时间变化的曲线图。目前,使用geom_文本,我能够标记Y值偏离0显著正值的关注点。但是,我也希望标记Y明显小于0的点。目前,对于geom_文本,我有: geom_text_repel(aes(label=ifelse(percent_change_price_SPY>0.35,as.character(DATE),''))) 我尝试在if语句中添加另一个条件 geom_text_repel(aes(label=ifelse((percent_change_price_S

我有一个股票价格随时间变化的曲线图。目前,使用geom_文本,我能够标记Y值偏离0显著正值的关注点。但是,我也希望标记Y明显小于0的点。目前,对于geom_文本,我有:

geom_text_repel(aes(label=ifelse(percent_change_price_SPY>0.35,as.character(DATE),'')))
我尝试在if语句中添加另一个条件

geom_text_repel(aes(label=ifelse((percent_change_price_SPY>0.35)|(percent_change_price_SPY<-.35),as.character(DATE),'')))

geom_text_repel(aes(label=ifelse((percent_change_price_SPY>0.35);(percent_change_price_SPY0.35,as.character(DATE),“”))+geom_text_repel(aes(label=ifelse(percent_change_price_SPY一个嵌套的geom_text和两个ifelse语句应该起作用,例如在这个玩具数据集中

library(data.table)
library(ggplot2)
library(ggrepel)

dat <- data.table(col1=c(rep("A",50), rep("B",50)), col2=rep(1:50,2), col3=runif(100, min=-1, max=1))

ggplot(data=dat, mapping=aes(x=col2, y=col3, color=col1)) +
geom_line() +
geom_text_repel(aes(label=ifelse((col3 > 0.9), col2, ifelse(col3 < -0.9, col2, ""))))
库(data.table)
图书馆(GG2)
图书馆(ggrepel)
dat 0.9),col2,ifelse(col3<-0.9,col2,“”))
在你的情况下,这将是一个大致如下的东西:

geom_text_repel(aes(label=ifelse((percent_change_price_SPY > 0.35), DATE, ifelse(percent_change_price_SPY < -0.35, DATE, ""))))
geom\u text\u repel(aes(标签=ifelse((百分比变化价格>0.35),日期,ifelse(百分比变化价格<-0.35,日期,”))
请注意,示例代码中的以下条件将无法按预期工作:

value<-0.35

valueYeah,原来我只需要使用
value0.35)|(百分比(变化)价格(价格)
geom_text_repel(aes(label=ifelse((percent_change_price_SPY > 0.35), DATE, ifelse(percent_change_price_SPY < -0.35, DATE, ""))))
value<-0.35