ggplot2: Automatic scaling to include complete contour lines in geom_density_2d

Viewed 1454

Hopefully this will be quick.

I have plotted the following chart using ggplot.

ggplot chart

with the code:

ggplot(ContourDummy,aes(x=Measure.Name1,y=Measure.Name2,colour=Category.Name))
+geom_density_2d()

My issue is that some of the contour lines are not complete.

Now if I scale my axis by adding the following...

+ scale_x_continuous(minor_breaks=0, breaks=seq(14,26,12),limits=c(14,26)) 
+ scale_y_continuous(minor_breaks=0, breaks=seq(50,100,50),limits=c(50,100)

I get the desired output.

But is there any way of automatically setting the limits? I want to be able to replicate this chart type automatically just by switching the data source, x, y and colour.

I don't particularly want to be fiddling around with scales every time.

1 Answers
Related