r - 如何将 % 符号添加到 ggplot
问题描述
我无法将 % 符号添加到 ggplot (R) (折线图)
这是我的情节代码:
ggplot(table) +
geom_bar(aes(x=year, y=order_cnt_in_thousends),stat="identity", fill="tan1", colour="sienna3")+
geom_line(aes(x=year, y=yearly_change ),stat="identity")+
geom_text(aes(label=yearly_change, x=year, y=yearly_change), colour="black")+
geom_text(aes(label=order_cnt_in_thousends, x=year, y=order_cnt_in_thousends), colour="black", vjust = -0.5) + scale_x_date(date_breaks = "1 year")
我试图将它添加到列中:
table$yearly_change <-paste(year_growth_table$yearly_change, "%")
但现在我遇到了问题,因为它是离散的而不是连续的。
解决方案
您可以使用 中的paste
函数aes()
使其成为带有 "%" 的字符串:
set.seed(1234)
df = data.frame(year=as.Date(c("2016-01-01","2017-01-01","2018-01-01")),order_cnt_in_thousends = sample(1000,3),yearly_change = sample(1000,3))
ggplot(df) +
geom_bar(aes(x=year, y=order_cnt_in_thousends),stat="identity", fill="tan1", colour="sienna3")+
geom_line(aes(x=year, y=yearly_change ))+
geom_text(aes(label=paste(yearly_change,"%"), x=year, y=yearly_change), colour="black")+
geom_text(aes(label=order_cnt_in_thousends, x=year, y=order_cnt_in_thousends), colour="black", vjust = -0.5) + scale_x_date(date_breaks = "1 year")
推荐阅读
- reactjs - 无法使用酶和 Cheerio 在 React 中找到用于单元测试 d3 组件的 svg 元素
- azure-devops - 将所有 Azure DevOps 项目从一个用户移动到另一个用户?
- javascript - svg元素隐藏如果不在容器中
- android - 4 按钮中的随机场
- android - android webview没有水平滚动
- c - tar.gz 文件中的文件意外结束
- javascript - 将解码的路径转换为javascript中的坐标?
- python - 使用 TF 2.0 为 Tensorflow/Keras 模型提供嵌入层问题
- arrays - 如何使用 JSON 路径从 JSON 数组中将不存在的道具提取为 null 或空字符串
- kubernetes-pod - 我的 init 容器不断失败,我得到的错误是 - “Init:RunContainerError”