柱状图
普通的柱状图使用barplot函数。其参数horiz=TRUE表示水平画图,beside=TRUE表示如果是多组数据的话,并排画图,否则原位堆叠画图。
> op <- par(mfrow = c(1, 2))
> counts <- table(mtcars$vs, mtcars$gear)
> barplot(counts, main = "Car Distribution by Gears and VS", xlab = "Number of Gears",
+ col = c("darkblue", "red"), legend = rownames(counts), horiz = TRUE)
> barplot(counts, main = "Car Distribution by Gears and VS", xlab = "Number of Gears",
+ col = c("darkblue", "red"), legend = rownames(counts), beside = TRUE)
> par(op)
柱状统计图使用hist函数。其breaks参数设置每组的范围。可以使用loess回归后计算出一条拟合曲线。对于hist图像,还可以使用density函数拟合曲线。
> h <- hist(mtcars$mpg, breaks = 12)
> lo <- loess(h$counts ~ h$mids)
> x <- seq(min(h$breaks), max(h$breaks), (max(h$breaks) - min(h$breaks))/1000)
> lines(x, predict(lo, x), col = "red")
> dens <- density(mtcars$mpg)
> t <- dens$n * length(dens$x)/sum(h$counts)/length(h$counts)/sum(h$density)
> lines(dens$x, dens$y * t, col = "blue")
您好!
我在绘制箱式图时boxplot(Pset, col = cols, ylim = c(0.95,1.22), main = “NUSE”,las = 2),图中细胞名称如MDB-MB-231,会自动变成MDA.MB.231。这该怎么调整?
非常感谢!
boxplot(Pset, col = cols, ylim = c(0.95,1.22), main = “NUSE”, las = 2, names=c(…, “MDB-MB-231”, …))。中间的…要换成MDB-MB-231前后的相应的名称。