tag:blogger.com,1999:blog-7615405652040127128.post4628491533117337157..comments2017-08-20T09:18:45.245-07:00Comments on gRaphics!: Plotting data and distribution simultaneously (with ggplot2)Anonymoushttp://www.blogger.com/profile/11100544715766158396noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-7615405652040127128.post-3524015715826249952012-05-16T14:56:14.648-07:002012-05-16T14:56:14.648-07:00Dear Sir,
Thank you for the excellent post.
What...Dear Sir,<br /><br />Thank you for the excellent post.<br /><br />What is the code for:<br /><br />col=subspadam888https://www.blogger.com/profile/01031203990226753277noreply@blogger.comtag:blogger.com,1999:blog-7615405652040127128.post-64031800591166041092012-05-16T13:25:28.313-07:002012-05-16T13:25:28.313-07:00I did insert all changes easy to do...
I'll ...I did insert all changes easy to do... <br /><br />I'll think about the dividing line later, Paul...Anonymoushttps://www.blogger.com/profile/11100544715766158396noreply@blogger.comtag:blogger.com,1999:blog-7615405652040127128.post-56118521233328005292012-05-16T12:39:16.023-07:002012-05-16T12:39:16.023-07:00Thanks Paul,
I'll try to move the legend, alt...Thanks Paul,<br /><br />I'll try to move the legend, although I may have to create a new empty plot to stick it up there... I didn't know until yesterday of the existence of geom_blank() which should let me do exactly that...<br /><br />As for suggestion number two, it may be a bit tough... In base graphics I'd use 'arrows' to translate the plots up and down... in ggplot I may be able to fudge it... I'll give it a go together with Andrew suggestions tomorrow...Anonymoushttps://www.blogger.com/profile/11100544715766158396noreply@blogger.comtag:blogger.com,1999:blog-7615405652040127128.post-80600810984146121292012-05-16T11:50:17.565-07:002012-05-16T11:50:17.565-07:00Luca,
I love the plot! I have two suggestions:
...Luca, <br /><br />I love the plot! I have two suggestions:<br /><br />1) move the legend to the top right area vplayout1(1,5)(..should be pretty easy, right)<br /><br />2) separate the two density plots (grey and specular) with a little whitespace (because I find it essential to have the reference straight-line when looking at density plots). (that seems harder).<br /><br />What do you think of that?<br />-PaulPaulhttps://www.blogger.com/profile/10309070147122994040noreply@blogger.comtag:blogger.com,1999:blog-7615405652040127128.post-42120024184421981172012-05-16T11:47:55.806-07:002012-05-16T11:47:55.806-07:00Thanks for such a quick update, and keep the good ...Thanks for such a quick update, and keep the good examples coming!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7615405652040127128.post-36664177132295982972012-05-16T10:52:52.406-07:002012-05-16T10:52:52.406-07:00Code's been added - I took it (and adapted it)...Code's been added - I took it (and adapted it) from http://wiki.stdout.org/rcookbook/Graphs/Colors%20(ggplot2)/#a-colorblind-friendly-paletteAnonymoushttps://www.blogger.com/profile/11100544715766158396noreply@blogger.comtag:blogger.com,1999:blog-7615405652040127128.post-8492241715598146842012-05-16T10:40:14.120-07:002012-05-16T10:40:14.120-07:00Hello Luca,
Very interesting graph. Could you pr...Hello Luca,<br /><br />Very interesting graph. Could you provide the code necessary to generate the palette (i.e. cbnbPalette).<br /><br />Thanks,<br />JohnJ A Thompsonhttps://www.blogger.com/profile/07240598378968773691noreply@blogger.comtag:blogger.com,1999:blog-7615405652040127128.post-13737887464317594642012-05-16T10:02:16.073-07:002012-05-16T10:02:16.073-07:00Thank you for your comments, Andrew. Very insightf...Thank you for your comments, Andrew. Very insightful.<br /><br />I am aware of the issues of scaling between the 'overall' density and the 'by group' density - I'll try to update the plot and code to reflect your suggestions.<br /><br />From now on I'll do my best to make the code totally self-contained, too...Anonymoushttps://www.blogger.com/profile/11100544715766158396noreply@blogger.comtag:blogger.com,1999:blog-7615405652040127128.post-76219022158872073992012-05-16T08:31:26.960-07:002012-05-16T08:31:26.960-07:00Nice example, one thing I would nit-pick though is...Nice example, one thing I would nit-pick though is that the area of the reflection of the density estimate for the full distribution is not the same as the area estimate for the sub-groups. <br /><br />This is difficult to amend though, as the kernel density estimate will be different for the subgroups than it will be for the total distribution. Some experimentation suggests that using counts instead of density, and then on the reflected distribution using a stacked density estimate (which is only possible when using counts instead of density) constrains the areas to be the same. Example given below using your same 'df' (and I'm sure some more can be done to make it look alittle nicer);<br /><br />p5 <- ggplot(df)<br />p5 <- p5 + geom_density(aes(x = x, y = ..count.., fill = z, alpha=0.4))<br />p5 <- p5 + geom_density(aes(x = x, y = -..count.., col = z, fill=NA), position = "stack")<br />p5<br /><br />One might also want the density estimates for x and y to be equal as well, but I'm not sure how to accomplish that. <br /><br />One could probably also make a case for the density estimate to be scaled (allows comparisons between sub-groups more easily), but I think first blush you would not want to do this.<br /><br />Also, in the future I would appreciate it if you made the code completely self contained (such as including the data(iris) statement, as well as the code used to make the color palette). Also in my current version I needed to load the grid library.<br /><br />Thank you for the example!<br />AndyAnonymousnoreply@blogger.com