如何使用 ggplot 绘制反向(互补)ecdf? [英] How to plot reverse (complementary) ecdf using ggplot?

查看:34
本文介绍了如何使用 ggplot 绘制反向(互补)ecdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用 stat_ecdf 来绘制我的累积频率图.

I currently use stat_ecdf to plot my cumulative frequency graph.

这是我使用的代码

    cumu_plot <- ggplot(house_total_year, aes(download_speed, colour = ISP)) + 
                 stat_ecdf(size=1)

但是我希望 ecdf 被反转(补充 ecdf).有什么最简单的方法可以做到这一点吗?

However I want the ecdf to be reversed(complementary ecdf). Any ideas of the easiest way to do this?

干杯!

推荐答案

因为似乎没有更简单的方法来绘制逆 ecdf,所以我做了以下工作,以防有人正在寻找解决方案:

Since seems like there's no easier way to plot the inverse ecdf, here is what I've done in case someone is looking for a solution:

  1. 从ecdf函数中提取信息并存入新列

  1. extract the information from ecdf function and store it in the new column

house_total_year_ecdf <- ddply(house_total_year, c("ISP"), mutate,
      ecdf = ecdf(download_speed)(unique(download_speed))*length(download_speed))

#transforming the scale to (0,1)
house_total_year_ecdf_2 <- ddply(house_total_year_ecdf, "ISP", mutate, 
      ecdf =scale(ecdf,center=min(ecdf),scale=diff(range(ecdf))))

  • 使用 geom_step 和 y = 1-ecdf 绘制图形

  • Plot the graph using geom_step and with y = 1-ecdf

    ggplot(house_total_year_ecdf_2, aes(download_speed,1-ecdf, colour = ISP)) +
    geom_step()
    

  • 这篇关于如何使用 ggplot 绘制反向(互补)ecdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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