
P + geom_smooth(data = ggplot_build(p)$data], Geom_point(stat = 'bin', binwidth = 0.1, aes(colour=factor(col), group=factor(col)))+ P <- ggplot(data = df, aes(x = con_rns))+ library(poweRlaw)ĭf <- ame(con_rns =con_rns,col=sample(1:3,size = length(con_rns),replace = T)) I approached this in the same way but it was necessary for me to create a 'group' aesthetic so this data could be kept in the ggplot_build data.

The additional problem was how to split the plot by different colour groups. Then I added the binned data from the plot which can be found with ggplot_build(p)$data (and reversed the log10 transformation) p + geom_smooth(data = ggplot_build(p)$data], One way would be to recover the binned data from the plot using ggplot_build()įirst I made the plot without the line of best fit: p <- ggplot(data = df, aes(x = con_rns))+ How can I plot different color point group and color line group in log-log axis? like this: If I want to plot different group, how can I draw it? The data are df <- ame(con_rns =con_rns,col=sample(1:3,size = length(con_rns),replace = T)). I know, I can manually bin data, provide "y" explicitly and then plot the line, like this ggplot(data = ame(a = rnorm(50,0,1),b=5+rnorm(50,2,1)),mapping = aes(x = a,y=b))+īut I want to know, how can I plot trend line with this code ( geom_point(stat = 'bin', binwidth = 0.1)).

Geom_smooth(stat = 'bin',mapping = aes(x=con_rns),method = "lm",se=FALSE)+ Geom_point(stat = 'bin', binwidth = 0.1)+ #convert to ame format for ggplot2ĭf <- ame(con_rns =con_rns) However, if I do not explicitly provide "y" parameter, I do not know how to plot. so if I plot them on log-log axis, and they will be a straight line. I need plot a data vector, which follow power law distribution.
