Create a non-overlapping area by area using ggplot2

I have some data cleared and processed from the Internet in this form:

>head(dat) count name episode percent 1 309 don 01-a-little-kiss 0.27081507 2 220 megan 01-a-little-kiss 0.19281332 3 158 joan 01-a-little-kiss 0.13847502 4 113 peggy 01-a-little-kiss 0.09903593 5 107 roger 01-a-little-kiss 0.09377739 6 81 pete 01-a-little-kiss 0.07099036 

I am trying to create a table with a breakdown by regions similar to that here: Creating a breakdown by region using ggplot2

When i do

 require(RCurl) require(ggplot2) link <- getURL("http://dl.dropbox.com/u/25609375/so_data/final.txt") dat <- read.csv(textConnection(link), sep=' ', header=FALSE, col.names=c('count', 'name', 'episode')) dat <- ddply(dat, .(episode), transform, percent = count / sum(count)) ggplot(dat, aes(episode, percent, group=name)) + geom_area(aes(fill=name, colour=name), position='stack') 

enter image description here

I get this weird diagram.

I want the areas not to overlap with each other, and to fill the entire canvas, since the total percentage for each episode ratio is 100%.

+6
source share
1 answer

That was interesting. You are missing one line (Lane did not appear in Tea Leaves ...?), Therefore

 dat2 <- rbind(dat,data.frame(count = 0,name = 'lane', episode = '02-tea-leaves',percent = 0)) ggplot(arrange(dat2,name,episode), aes(x = episode,y = percent)) + geom_area(aes(fill=name,group = name), position='stack') 

enter image description here

seems to work. But that, too, had to be in the correct order, and I don’t quite understand why.

+8
source

Source: https://habr.com/ru/post/914599/


All Articles