像素数:图片上的最小成像单位的数目。评价一个设备的像素值,一般使用宽高像素的乘积表示,如1000px * 1500 px
尺寸:指图像打印后的物理尺寸,一般用厘米/米或者(英)寸表示,1英寸(inche)=2.54厘米
分辨率:单位尺寸下像素点的数目,越高图像越细腻。计算方式为 分辨率=像素数/尺寸,是真正衡量设备清晰度的指标,单位一般为像素/英寸或者像素/厘米。
容量:图像文件的存贮空间,也就是文件的大小,一般以Kb和Mb来表示。
ps:平时所说的1200万像素的手机,是指该手机的像素数。
在R绘图中也需要调整最后图片的上述参数。一般我们使用一下函数对图片进行导出:
这里也写了一个shiny程序用于手动导出png或pdf
1. barplot函数
>a=matrix(1:18,2)
>a
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,] 1 3 5 7 9 11 13 15 17
[2,] 2 4 6 8 10 12 14 16 18
>class(a) #查看a数据类型
[1] "matrix"
注意barplot函数对象要么是向量,要么是矩阵,若不是,则要进行数据数据类型进行转换
>barplot(d) #所有参数默认
>?barplot
常见参数就不赘述了,几个个人认为比较重要参数如下
names.arg----在每个条形图或条形图下绘制的名称向量。 如果省略此参数,那么如果它是向量,则从height的names属性中获取名称;如果它是矩阵,则从列名称中获取名称。
legend.text----数据为矩阵的时候用,如果legend.text为true,则height的行名称非空时将用作标签。
horiz----默认false,为竖直条形图,改为TRUE,为水平条形图
beside---如果为FALSE,则将高度列描绘为堆叠的条,如果为TRUE,则将列描绘为并列的条
space---每根柱子之前留出的空间量(以平均柱子宽度的一部分为单位)。 可以以单个数字或每个小节一个数字的形式给出。 如果height是一个矩阵,并且next为TRUE,则可以用两个数字指定空间,其中第一个是同一组中的条形之间的间隔,第二个是组之间的间隔。 如果未明确给出,则如果height为矩阵,并且next为TRUE,则默认为c(0,1),否则为0.2。
还有很多参数可以通过help()查询
>barplot(a,names.arg = c('1','2','3','4','5','6','7','8','9'),beside = TRUE,horiz = TRUE,col = rep(c('blue','green','gray'),3),legend.text = TRUE)
>barplot(a,names.arg = c('1','2','3','4','5','6','7','8','9'),beside = F,horiz = TRUE,col = rep(c('blue','green'),2),legend.text = TRUE)
>barplot(a,names.arg = c('1','2','3','4','5','6','7','8','9'),beside = F,horiz = F,col = rep(c('blue','green'),2),legend.text = TRUE)
2.ggplot2包
安装加载包
install.package('ggplot2')
library(ggplot2)
#创建矩阵
data<-data.frame(Sample<-c(rep('control1',3),rep('control2',3),rep('control3',3),rep('treat1',3),rep('treat2',3),rep('treat3',3),rep('treat4',3)), contion<-rep(c('Cell','Tissue','Organ'),7), value<-c(503,264,148,299,268,98,363,289,208,108,424,353,1,495,168,152,367,146,48,596,143))
colnames(data)=c('sample',"contion","value")
ggplot(data,mapping = aes(Sample,value,fill=contion))+geom_bar(stat='identity',position='fill') +labs(x = 'Sample',y = 'frequnency') +theme(axis.title =element_text(size = 16),axis.text =element_text(size = 14, color = 'black'))+theme(axis.text.x = element_text(angle = 45, hjust = 1))
#ggplot函数,geom从数据到几何图像,geom_bar为柱状图,geom_line为线型图等,aes形成映射,x轴为sample,y轴为value,堆叠为contion,geom_bar()函数为建立柱状图,stat参数-统计变换,position参数为柱状图形式,position= 'fill'(图形元素堆叠且高度标准化为1),position= 'stack'(图形堆叠图),参数position= 'dodge'(并列数据,非堆叠展示),coord画图在某个坐标系中,facet将绘图窗口分成若干子窗口用来生成数据中不同子集的图形
# labs为标题,theme为设置标题参数,axis.title为轴标题信息,axis.text为轴注释文本,axis.text.x表示设置x轴的信息,还有更多参数详查ggplot2包
ggplot(data,mapping = aes(Sample,value,fill=contion))+geom_bar(stat='identity',position='fill') +labs(x = 'Sample',y = 'frequnency') +theme(axis.title =element_text(size = 16),axis.text =element_text(size = 14, color = 'black'))+theme(axis.text.x = element_text(angle = 45, hjust = 1))+coord_flip() #加的函数可实现水平柱状图展示
ggplot(data,mapping = aes(Sample,value,fill=contion))+geom_bar(stat='identity',position='stack') +labs(x = 'Sample',y = 'frequnency') +theme(axis.title =element_text(size = 16),axis.text =element_text(size = 14, color = 'black'))+theme(axis.text.x = element_text(angle = 45, hjust = 1))
ggplot(data,mapping = aes(Sample,value,fill=contion))+geom_bar(stat='identity',position='dodge') +labs(x = 'Sample',y = 'frequnency') +theme(axis.title =element_text(size = 16),axis.text =element_text(size = 14, color = 'black'))+theme(axis.text.x = element_text(angle = 45, hjust = 1))