0

I am trying to plot a density with the following function. However It doesn't achieve the look I'm going for... I was wondering if there was a way to make the left and right edges of the plot smooth down to the baseline (so that it no longer has a square edge on the left and right.)

fig1<-ggplot(data=mtcars, aes(x=mpg, fill=as.factor(am))) +
      geom_density(aes(y=..density..), poisition = "identity", color = "black", alpha = 0.5) +
      geom_rug(aes(colour = as.factor(am))) +
      scale_x_continuous() +
      labs(fill = "Transmission", colour = "Transmission")
fig1
Jeff
  • 1

1 Answers1

2

Just replace

scale_x_continuous()

with

xlim(0,45)

to extend the x-axis. By default ggplot uses the ranges of the observed values. The density does not impact the range.

MrFlick
  • 195,160
  • 17
  • 277
  • 295