Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cut off density plot in ggplot2

Tags:

r

ggplot2

I use

frame <- read.table(paste('data', fname, sep="/"), sep=",", header=TRUE)
colnames(frame) <- c("pos", "word.length")
plot <- ggplot(frame, aes(x=pos, y=word.length)) + xlim(0,20) + ylim(0,20) + geom_density2d() + stat_density2d(aes(color=..level..))
png(paste("graphs/", fname, ".png", sep=""), width=600, height=600)
print(plot)
dev.off()

to create plots, but they get cut off. How do I fix this?

http://ompldr.org/vZTN0eQ

The data I used to create this plot: http://sprunge.us/gKiL

like image 309
Reactormonk Avatar asked Jun 05 '12 16:06

Reactormonk


1 Answers

According to the ggplot2 book, you use scale_x_continuous(limits=c(1,20)) instead of xlim(1,20) for that.

like image 53
Reactormonk Avatar answered Nov 09 '22 09:11

Reactormonk