我的代码:如何将图例添加到多个条形图?
#!/usr/bin/R
par(mfrow=c(4,1))
fcm <-c(13.0,12.5,11.8)
gk <-c(10.9 , 10.5 , 10.2)
gg <-c(12.0 , 11.0 , 10.8)
data1 <- rbind(fcm,gk,gg)
colnames(data1) <- c(5,6,7)
fcm <-c(1.29,1.25,1.22)
gk <-c(1.19,1.05,1.00)
gg <-c(1.10,1.02,1.07)
data2 <- rbind(fcm,gk,gg)
colnames(data2) <- c(5,6,7)
fcm <-c(10.5,9.8,8.8)
gk <-c(11.0,8.4,10.0)
gg <-c(2.0,1.8,1.6)
data3 <- rbind(fcm,gk,gg)
colnames(data3) <- c(5,6,7)
fcm <-c(0.33,0.29,0.31)
gk <-c(0.49,0.40,0.35)
data4 <- rbind(fcm,gk)
colnames(data4) <- c(5,6,7)
barplot(as.matrix(data1),ylim=c(0,20),main="P wave",
xlab="number of clusters", ylab="traveltime rms(ms)",
col=c("red", "black", "green"), beside=TRUE)
barplot(as.matrix(data2),ylim=c(0,2),main="MT",
xlab="number of clusters", ylab="MT functions",
col=c("red", "black", "green"), beside=TRUE)
barplot(as.matrix(data3),ylim=c(0,20),main="XBI",
xlab="number of clusters", ylab="index value",
col=c("red", "black", "green"), beside=TRUE)
barplot(as.matrix(data4),ylim=c(0,0.6),main="NCE",
xlab="number of clusters", ylab="index value",
col=c("red", "black"), beside=TRUE)
legend(legend = c("fcm","gk","gg"), fill = c("red", "black", "green"))
dev.copy(png,"dp.png",width=9,height=6,units="in",res=200)
dev.off()
我已经尝试了传说中的右上方,但它重叠image.Anyone知道如何添加传说,位置也不是那么进口只是为了visible.I正在提交这对一个科学杂志我需要一个不错的布局。
它必须是基础R?或者它可以是ggplot?最好的方法可能是在底部或顶部有四个分组图像和一个图例。一般来说,红色和绿色不是很好用,不是每个人都能看到它们之间的对比。 – Heroka
@Heroka它可以是ggplot我很好。 –
如果你正在使用R gui,那么有关这个传说的一件事就是它第一次写入dev.new()这个传说非常巨大,而且都是奇怪的。其他一些选项是调整开发窗口的大小,然后重新运行代码,图例的大小将发生显着变化。或者,您也可以将图表写入一个文件(例如:pdf(width = 11,height = 8.5)for landscape)。 – darwin