r - 在 scale_continuous ggplot2 中使用手动功能
问题描述
此代码在没有 scale_y_continuous geom 的情况下完美运行。为什么当我尝试在 scale_y_continuous geom 中使用手动函数时,此代码会返回错误:
library('tibble')
library("ggplot2")
df <- tibble(x=c(1:5),
y=c(11:15))
MyFunction <- function(x){
if(x>12){
return(paste0('$', x))
}else{
return(paste0('&', x))
}
}
ggplot(df, aes(x,y))+
geom_line()+
scale_y_continuous(
labels = function(x) MyFunction(x)
)
错误文字:
Warning message:
In if (x > 12) { :
the condition has length > 1 and only the first element will be used
解决方案
推荐阅读
- git - How to push work to my own private repo while still pulling updates from Github?
- go - 如何使用 Protobuf 的时间戳库和 Go 的时间库
- dart - 如何将 RevealedOffset 转换为颤振飞镖中的数字
- linux - 发生上游错误时如何从标准输入回滚 Vertica 副本?
- forms - 单击时如何更改动态单选按钮样式
- r - 取出适合图案的部分字符串
- c# - 使用 C# getter 属性重复反序列化
- elasticsearch - ElasticSearch 配置文件 API `time_in_nanoseconds` 值高于 `took` 时间
- python - Python 文本替换为 for 循环
- aws-lambda - 无服务器开始不从 yaml 文件创建本地 DynamoDB 数据库