3

I use function fitdist in package fitdistrplus to get the best distribution fitted to my data and draw the ppcomp figure , I use the example codes of ?fitdistrplus to replace my data and codes.

data(groundbeef)
serving <- groundbeef$serving
fitW <- fitdist(serving, "weibull")
fitg <- fitdist(serving, "gamma")
fitln <- fitdist(serving, "lnorm")
ppcomp(list(fitW, fitg, fitln), legendtext=c("Weibull", "gamma", "lognormal"))

ppcomp

So far so good! But look at the left bottom of the pic, there is some space, or the axes does not start from zero!

So I googled and find two methods: One method in the base plot, xaxs and yaxs are used.

set.seed(1234)
x <- runif(100, min=0, max=100)
y <- runif(100, min=0, max=100)
plot(x,y,xaxs="i",yaxs="i",xlim=c(0,100),ylim=c(0,100))

base plot

Another method in the ggplot2, expand=c(0,0) is used.

df <- data.frame(x=x,y=y)
ggplot(df,aes(x,y)) + geom_point() + scale_x_continuous(expand = c(0,0)) + scale_y_continuous(expand = c(0,0))

expand

So I try to use these two methods to draw the ppcomp figure,

ppcomp(list(fitW, fitg, fitln), legendtext=c("Weibull", "gamma", "lognormal"),xaxs="i",yaxs="i")

but error occurs:

Error in legend(x = xlegend, y = ylegend, bty = "n", legend = legendtext,  : 
  unused arguments (xaxs = "i", yaxs = "i")

So, what should I do to complete the goal without the error, or what is the right codes?

Ling Zhang
  • 281
  • 1
  • 3
  • 13

1 Answers1

1

The problem seems to be that the ... argument in ppcomp (which accepts the extra arguments) is given to both plot and legend and legend does not know what to do with xaxs.

Options are:

1) Run ppcomp with xaxs, which will make the plot and then add the legend separately.

2) Use fix(ppcomp) to delete the ... from the legend commands.

3) Recode ppcomp to use ggplot and set the options as you please.

Richard Telford
  • 9,558
  • 6
  • 38
  • 51
  • Thank you, Sir, I tried Options 2, and it works. But as to options 1, it does not work. And about Options 3, I am not good at coding, so I do not have a try. – Ling Zhang Jul 04 '16 at 10:57