6
我有一個3行乘以5列的構面圖。每行顯示分佈在不同範圍的數據。爲了正確顯示我的數據,以便顯示所有內容,我不設置y軸限制。更改ggplot2中某個構面圖的每一行的y軸限制
這裏是我的代碼:
require(reshape2)
library(ggplot2)
library(RColorBrewer)
fileName = paste("./data_test.csv", sep = "")
## data available here: https://dl.dropboxusercontent.com/u/73950/data_test.csv
mydata = read.csv(fileName,sep=",", header=TRUE)
dataM = melt(mydata,c("id"))
dataM = cbind(dataM,
colsplit(dataM$variable,
pattern = "_",
names = c("Network_model", "order", "category")))
dataM$variable <- NULL
dataM <- dcast(dataM, ... ~ category, value.var = "value")
dataM$minCut <- NULL
dataM$nbr_communities <- NULL
dataM$mean_community_size <- NULL
dataM$density <- NULL
my_palette <- colorRampPalette(rev(brewer.pal(11, "Spectral")))
dataM = melt(dataM, id.vars = c("Network_model", "order", "nodesRemoved", "id"))
my_palette = c(brewer.pal(5, "Blues")[c(4)], brewer.pal(5, "Set1")[c(3)])
ggplot(dataM, aes(x= nodesRemoved ,y= value, group= order, color= order)) +
geom_point(size = .6,alpha = .15,position="jitter") + ## increased size
stat_smooth(se = FALSE, size = .5, alpha = .1, method = "loess") +
scale_color_manual(values=my_palette) +
theme_bw() +
theme(plot.background = element_blank(),
axis.line = element_blank(),
legend.key = element_blank(),
legend.title = element_blank(),
axis.text.x = element_text(size = 8),
axis.text.y = element_text(size = 8)
) +
scale_y_continuous("Value") +
scale_x_continuous("Time", limits=c(0, 100)) +
facet_grid(variable ~ Network_model,scales="free")
將會產生這樣的:
現在,我想每個三排選擇性地設定限制,使第一排是極限= c(1.9,3),第二個是極限= c(0,1),第三個是極限= c(.3,.7)。
我該如何在ggplot2中實現這一點?
這是可能與面,但它並不容易。如果我是你,我會做三個ggplots,每行一個。然後,您可以用傳統方式設置y軸限制,然後將這些行粘貼在一起,例如'grid.arrange'。 (我懷疑你會在代碼中得到任何答案,除非你的例子可以重現。) – Gregor 2014-12-04 18:29:01
儘管如果你可以用'ggplot'設置限制,試試'scale =「free_y」'而不是'scales = 「免費」'。沒有看到你的數據,就不可能猜測這是你想要的。 – Gregor 2014-12-04 18:32:29
謝謝Gregor,我添加了數據集和完整的代碼!乾杯! – Rodolphe 2014-12-04 18:59:21