我有以下代码:
install.packages("tidyverse")
library("tidyverse")
data(diamonds)
ggplot(data=diamonds)+
geom_point(mapping=aes(x=carat,y=price),color="blue")+
geom_hline(aes(yintercept=max(price)),
color="seagreen")+
annotate("text",x=3.5,y=19600,label=
scales::comma(max(diamonds$price),
accuracy=1),
size=5,color="seagreen",
fontface="bold.italic")+
facet_wrap(facets = "cut")
My current result is shown as the graphic below: I want to facet each "cut" level, and show the prices against carats. With the geom_hline, I want to show the highest price in each facet. However, I do not know how to do it.
我试着查找类似的问题,发现了这篇帖子: Different `geom_hline()` for each facet of ggplot个
这个问题与我的类似,但我不知道如何遵循建议的解决方案:如何将每个方面划分为不同的列?有没有办法在不修改原始数据库的情况下做到这一点?
谢谢大家