且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在密度分布的顶部绘制中位数

更新时间:2023-11-23 23:22:22

这可能只是一个开始(但是由于颜色,它不太可读).我的想法是在用于绘制中位数线的数据内创建一个"y"位置.这有点武断,但我希望y位置在0.2到1之间(以很好地适合绘图).我是通过sequence-command来完成的.然后,我尝试按中位数价格订购(效果不佳).这是任意的.

This might be a start (but it's not very readable due to the colors). My idea was to create an 'y'-position inside the data used to plot the lines for the medians. It's a bit arbitrary, but I wanted y-positions to be between 0.2 and 1 (to nicely fit on the plot). I did this by the sequence-command. Then I tried to order it (didn't do a lot of good) by the median price; this is arbitrary.

#scatter y-pos over plot
dia_me$y_pos <- seq(0.2,1,length.out=nrow(dia_me))[order(dia_me$price,decreasing = T)]


ggplot(dia, aes(x=price, y=..density.., color = cut, fill = cut), legend=TRUE) +
  labs(title="diamond price per cut") +
  geom_density(alpha = 0.2) +
  geom_vline(data=dia_me, aes(xintercept=price, colour=cut),
             linetype="dashed", size=0.5) +
  scale_x_log10() +
  geom_text(data = dia_me, aes(label = price, y=y_pos, x=price))