2015-04-12 30 views
5

下面是我想要包含在一篇論文中的情節。問題是我的陰謀的寬度是小(使X-axix不可讀在所有)如何在ggplot2中放大我的繪圖寬度?

這裏是GGPLOT2代碼myCode.r

require("ggplot2") 

all <- read.csv(file="benchmark/bench.query.csv", head=TRUE, sep=";") 

w <- subset(all, query %in% c("sort.q1", "sort.q2", "sort.q3", "sort.q4", "sort.q5")) 

w$rtime <- as.numeric(sub(",", ".", w$rtime, fixed=TRUE)) 

p <- ggplot(data=w, aes(x=query, y=rtime, colour=triplestore, shape=triplestore)) 
p <- p + scale_shape_manual(values = 0:length(unique(w$triplestore))) 
p <- p + geom_point(size=4) 
p <- p + geom_line(size=1,aes(group=triplestore)) 
p <- p + labs(x = "Requêtes", y = "Temps d'exécution (log10(ms))") 
p <- p + scale_fill_continuous(guide = guide_legend(title = NULL)) 
p <- p + facet_grid(trace~type) 
p <- p + theme_bw() 

ggsave(file="bench_query_sort.pdf") 

print (p) 

我已經環顧四周,看看如何擴大情節,但我什麼也沒找到。

任何關於在我的代碼中添加/刪除/修改的想法?

plot

+3

Jaap的答案解決了擴大的問題。此外,你可能想旋轉x的標記:'p = p + theme(axis.text.x = element_text(angle = 90,hjust = 1,vjust = 0.5))' – Arpi

回答

10

可能做到這一點最簡單的方法,是通過使用圖形設備(PNG,JPEG,BMP,TIFF)。

png(filename="bench_query_sort.png", width=600, height=600) 

ggplot(data=w, aes(x=query, y=rtime, colour=triplestore, shape=triplestore)) + 
    scale_shape_manual(values = 0:length(unique(w$triplestore))) + 
    geom_point(size=4) + 
    geom_line(size=1,aes(group=triplestore)) + 
    labs(x = "Requêtes", y = "Temps d'exécution (log10(ms))") + 
    scale_fill_continuous(guide = guide_legend(title = NULL)) + 
    facet_grid(trace~type) + 
    theme_bw()  

dev.off() 

width的和height在像素:可以按如下方式設定的圖像的精確寬度和高度。這在準備用於在互聯網上發佈的圖像時特別有用。欲瞭解更多信息,請參閱?png的幫助頁面。

或者,您也可以使用ggsave來獲得所需的確切尺寸。您可以將尺寸:

ggsave(file="bench_query_sort.pdf", width=4, height=4, dpi=300) 

widthheight以英寸爲單位,與dpi可以設置圖像的質量。

+2

非常好的答案。我做了一些與'quartz(height = 11,width = 8.5)'非常相似的東西來獲得一個新的繪圖窗口,接着是'ggplot()'東西,接着是quartz.save('fname.pdf')'。最終的結果是一樣的,我永遠不必記住那些煩人的'dev.off()'命令。 –

相關問題