Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot reverse (complementary) ecdf using ggplot?

Tags:

r

reverse

ecdf

I currently use stat_ecdf to plot my cumulative frequency graph.

Here is the code I used

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

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

Cheers!

like image 814
Tara Sutjarittham Avatar asked May 14 '16 00:05

Tara Sutjarittham


1 Answers

From the help page of stat_ecdf:

Computed variables

x

x in data

y

cumulative density corresponding x

So this works:

p <- ggplot(dataframe_with_column_Z, aes(x=Z))

p + geom_line(aes(y = 1 - ..y..), stat='ecdf')

Output

like image 157
Christos Mitas Avatar answered Oct 07 '22 15:10

Christos Mitas