带有数据标签的多条线(R)
我想用数据标签绘制多行 ,但是到目前为止,我所有的尝试都返回了一条错误消息。
ggplot(data, aes(year)) +
geom_line(aes(y = var1), color = "#E20335", size = 1.5) +
geom_point(aes(y = var1), color = "#E20335", size = 3) +
geom_line(aes(y = var2), color = "#292753", size = 1.5) +
geom_point(aes(y = var2), color = "#292753", size = 3) +
scale_x_continuous(breaks = 2010:2020) +
scale_y_comma() +
labs(title = 'something',
subtitle = 'something',
x = 'This axis title intentionally left blank',
y = 'This axis title intentionally left blank',
caption = 'something')
我想将标签插入此代码中,以便将它们放置在数据点周围。任何帮助将不胜感激。
I would like to plot multiple lines with data labels but all my attempts have returned an error message so far.
ggplot(data, aes(year)) +
geom_line(aes(y = var1), color = "#E20335", size = 1.5) +
geom_point(aes(y = var1), color = "#E20335", size = 3) +
geom_line(aes(y = var2), color = "#292753", size = 1.5) +
geom_point(aes(y = var2), color = "#292753", size = 3) +
scale_x_continuous(breaks = 2010:2020) +
scale_y_comma() +
labs(title = 'something',
subtitle = 'something',
x = 'This axis title intentionally left blank',
y = 'This axis title intentionally left blank',
caption = 'something')
I want to insert the labels into this code, so that they are placed around data points. Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如评论中所建议的,您可以尝试使用
geom_label
。但是,如果您提供一个示例数据集,例如内置数据集或dput(data)
的输出,则更好。另外,包括library
您正在与您一起帮助人们帮助您。由于您没有指定要标记哪个变量,因此我在此图和数据中发布了一个示例,其中包括
mtcars
数据集和数据,通常最好将数据集重新设计为长格式,以便更容易要管理传奇,颜色和其他ggplot选项As suggested in the comment you can try with
geom_label
. However, it is better if you provide an example dataset such as an in-built dataset or the output ofdput(data)
. Also, include thelibrary
you are working with to help people help you. Since you do not specify which variable do you want to label I post an example with themtcars
datasetFor this kind of plot and data it is typically better to reshape the dataset to a long format so it is easier to manage legend, color and other ggplot options