将计算的值与ggplot2注释中的文本组合在一起 [英] Combine calculated value with text in ggplot2 annotation

查看:86
本文介绍了将计算的值与ggplot2注释中的文本组合在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ggplot2条形图,其中我想添加一个注释,它是部分计算值和部分自定义文本。如果我有一个数值数组LoadRecommentation,那么我就可以在我的生活中找到正确的搜索条件来找到一个例子。

希望能够使用LoadRecommendation的值以及像Loads这样的自定义文本创建如下所示的注释。下面的代码显然不起作用,但我不知道如何解决这个问题。

  ggplot(
PowerDrawMelt,aes(x = MillNames,y = value,fill = variable))+
geom_bar(stat =identity,position =identity,alpha = 1)+
annotate(text ,x = 1,y = 1,label =LoadRecommendation [3] +Loads)


解决方案

使用粘贴:

  ggplot(
PowerDrawMelt,aes(x = MillNames,y = value,fill = variable))+
geom_bar(stat =identity,position =identity,alpha = 1)+
annotate(text,x = 1, y = 1,label = paste(LoadRecommendation [3],Loads))


I have a ggplot2 bar chart in which I would like to add an annotation that's part calculated value and part custom text. I can't for the life of me think of the right search terms to use in SO to find an example.

If I have a numerical array "LoadRecommentation", I want to be able to create an annotation as below, with the value from LoadRecommendation as well as custom text like "Loads". The code below is clearly not going to work, but I'm not sure how to fix this.

ggplot(
  PowerDrawMelt, aes(x=MillNames, y=value, fill=variable)) +
  geom_bar(stat="identity", position = "identity", alpha=1) +
  annotate("text", x = 1, y = 1, label = "LoadRecommendation[3] + "Loads"")

解决方案

Use paste:

ggplot(
  PowerDrawMelt, aes(x=MillNames, y=value, fill=variable)) +
  geom_bar(stat="identity", position = "identity", alpha=1) +
  annotate("text", x = 1, y = 1, label = paste(LoadRecommendation[3], "Loads"))

这篇关于将计算的值与ggplot2注释中的文本组合在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆