2017-08-11 22 views
0

我正在嘗試在gglot2中製作一個看起來像this的圖。ggplot2在放大時會切掉我的身影部分

但是,我似乎現在有一個權衡其所有的方塊小象......或者在廣場放大和有部分之間切割 both displayed here as I may not add more pictures, yet

我的代碼遵循

if (!require('ggplot2')) install.packages('ggplot2'); library('ggplot2') 


Odds <- c(1.2,1,0.97,1,1.38,0.95,0.85,0.95) 
x <- c(5,3.5,0,-3.5,-5,-3.5,0,3.5) 
y <- c(0,3.5,5,3.5,0,-3.5,-5,-3.5) 

summed <- data.frame(Odds,x,y) 
d <- qplot(x, y, data=summed, colour =Odds) 
d + theme_classic(base_size = 14) + geom_point(size = 30, shape=15) + 
    scale_colour_gradient(low="grey", high = "black") + 
    ylab("") + 
    xlab("") + 
    scale_y_continuous(breaks=NULL) + scale_x_continuous(breaks=NULL) 

我希望你們中的一些人能幫助我。

+1

也許加上'expand_limits(x = c(-6,6),y = c(-6,6))' –

回答

0

GGplot在繪圖區域周圍出現某種「出血」或「呼吸」。你的geom_point的大小超出了這個空間。 解決方法是爲繪圖區域設置自定義限制。試試這個:

d <-qplot(x, y, data=summed, color =Odds) 
    d + theme_classic(base_size = 14) + geom_point(size = 30, shape=15) + 
     scale_colour_gradient(low="grey", high = "black") + 
     ylab("") + 
     xlab("") + 
     scale_y_continuous(breaks=NULL) + 
     scale_x_continuous(breaks=NULL) + 
     theme(aspect.ratio = 1) + ## Optional. Ensures you get a square shaped plot 
     expand_limits(x =c(min(x) - 1, max(x) + 1), ## Expands the limits, reads from your predefined "x" and "y" objects. 
         y =c(min(y)-1, max(y) +1)) 
相關問題