在图表(ggplot2)中用另一个文件的标签下标标题 [英] Subscript a title in a Graph (ggplot2) with label of another file

查看:381
本文介绍了在图表(ggplot2)中用另一个文件的标签下标标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序中,我有两个主要文件,第一个包含数据,第二个包含标签(或图形标题):

In my program I have two main files, the first with the data and the second with labels (or titles of my graphics):

文件总数1(数据)

3   10000   3   32039232    1   0.0017290351    2   0.0002781092
3   10001   3   32101193    1   0.0045398899    2   0.0032875689
3   1000    1   60233253    1   0.0022057964    2   6.747e-06
3   10002   3   32108182    1   0.0219913914    2   0.0102120679
3   10003   3   32133994    1   0.0007025013    2   0.0010197563
3   10004   3   32192498    1   0.0029210855    2   0.0036980008
3   10005   3   32230041    1   0.0005408603    2   0.0015782048
3   10006   3   32271305    1   1.099e-07       2   0.0033466856
3   10007   3   32289336    1   0.0185812303    2   0.0027349589
3   10008   3   32453784    1   0.0080117379    2   0.0003596759

文件腿(标签)

Áre de olho de lombo
Espessura de gordura subcutânea
pH0 inicial 
pH24 final
Perda por cocção
Força de cisalhamento
Cor L*
Cor a*
Cor b* 

我正在同一bash卡上同时使用linux命令和R,以绘制图形.我正在执行此脚本中的循环:

I am using linux commands and R simultaneously on the same bash card, to plot graphs. I'm doing looping in this script:

!/bin/bash

{1..9}中的l;

!/bin/bash

for l in {1..9}; do

R -q -e"leg&-read.table('leg', header = F,sep ='\ t'); write.table(leg,'lef1.txt',sep ='\ t',row.names = F,col.names = F); uni $ l <-read.table('./var/chrsnpvar_uni $ l',header = F); bi $ l <-read.table('./var/chrsnpvar_bi $ l ', 标头= F); map< -read.table('snp_map_clean',sep ='\ t',header = F); uni1 $ l = uni $ l [其中(uni $ l [,1] == 1& uni $ l [,2] == 3),]; bi1 $ l = bi $ l [ 其中(bi $ l [,1] == 2&bi $ l [,2] == 3),];总计$ l<-merge(uni1 $ l,bi1 $ l, by = c(2,4,5,6),all = T); write.table(total $ l,'total $ l.txt',sep ='\ t', row.names = F,col.names = F);库(ggplot2); tiff('./solution/cor $ l.tiff',宽度 = 10,高度= 6,单位='in',res = 75); ggplot(total $ l,aes(x = total $ l [,6],y = total $ l [,8]))+ geom_point()+ scale_x_continuous(breaks = round(seq(min(0),max(0.08),by = 0.01),2),limits = c(0,0.08))+ scale_y_continuous(breaks = round(seq(min(0),max(0.08),by = 0.01),2),limits = c(0,0.08) )+ geom_smooth(method = lm,color ='grey35',se = FALSE)+ geom_vline(xintercept = 分位数(total $ l [,6],0.95),lty = 2,size = 1,colour ='grey')+ geom_hline(yintercept =分位数(total $ l [,8],.95), lty = 2,size = 1,colour ='grey')+ ylab('Bicaracterística')+ xlab('Unicaracterística')+ theme_classic()+ 主题(axis.line.x = element_line(colour ='black',size = 1),axis.line.y = element_line(colour ='black',size = 1), axis.ticks.length = unit(4,'mm'),legend.title = element_blank(),axis.title.y = element_text(大小= 22),axis.title.x = element_text(size = 22),axis.text.x = element_text(size = 22),axis.text.y = element_text(大小= 22),图例.text = element_text(大小 = 22),title = element_text(size = 22))+注释('text',x = 0.005,y = 0.07,label ='A',size = 8)+注释('text',x = 0.06,y = 0.07,标签 ='B',size = 8)+注解('text',x = 0.005,y = 0.005,label ='C',colour ='white',size = 8)+注解('text',x = 0.06 ,y = 0.005,标签= 'D',size = 8)+ ggtitle(leg [$ l,1]); dev.off()"

R -q -e "leg<-read.table('leg', header=F,sep='\t');write.table(leg,'lef1.txt', sep='\t', row.names = F,col.names=F);uni$l<-read.table('./var/chrsnpvar_uni$l',header=F);bi$l<-read.table('./var/chrsnpvar_bi$l', header=F); map<-read.table('snp_map_clean',sep='\t',header = F);uni1$l=uni$l[ which(uni$l[,1]==1 & uni$l[,2]==3), ]; bi1$l=bi$l [ which(bi$l[,1]==2 & bi$l[,2]==3), ];total$l <- merge(uni1$l,bi1$l, by=c(2,4,5,6), all=T);write.table(total$l,'total$l.txt', sep='\t', row.names = F,col.names=F);library(ggplot2);tiff('./solution/cor$l.tiff', width =10 , height = 6, units = 'in',res = 75 ); ggplot(total$l,aes(x=total$l[,6], y=total$l[,8])) + geom_point() + scale_x_continuous(breaks = round(seq(min(0), max(0.08), by = 0.01),2),limits=c(0,0.08))+ scale_y_continuous(breaks = round(seq(min(0), max(0.08), by = 0.01),2),limits=c(0,0.08)) + geom_smooth(method=lm , color='grey35', se=FALSE)+ geom_vline(xintercept = quantile(total$l[,6],0.95),lty=2,size=1,colour='grey')+ geom_hline(yintercept = quantile(total$l[,8], .95), lty=2,size=1,colour='grey') + ylab('Bicaracterística') + xlab('Unicaracterística')+ theme_classic()+ theme(axis.line.x=element_line(colour='black',size=1),axis.line.y=element_line(colour='black',size=1), axis.ticks.length= unit(4,'mm'),legend.title = element_blank(),axis.title.y = element_text(size = 22), axis.title.x = element_text(size = 22),axis.text.x=element_text(size = 22),axis.text.y=element_text(size = 22), legend.text=element_text(size = 22), title=element_text(size =22)) + annotate('text', x = 0.005, y=0.07, label = 'A',size=8) + annotate('text', x = 0.06, y=0.07, label = 'B',size=8)+ annotate('text', x = 0.005, y=0.005, label = 'C', colour='white', size=8)+ annotate('text', x = 0.06, y=0.005, label = 'D',size=8)+ggtitle(leg[$l,1]); dev.off()"

完成

程序正常,我只需要在图形标题中以下标形式编写"pH24 final"的24和"pH0 Inicial"的0,以使用命令.有谁知道我可以通过使用另一个文件的标签来做到这一点?

The program is ok, I just need to write the 24 of "pH24 final" and 0 of "pH0 Inicial" in subscript form in my graphic titles, to write the titles from the label file I am using the commandggtitle(leg[$l,1]). Does anyone know how I can do this by using the label of another file?

推荐答案

看看是否可以给您一些想法.在基数R中使用数学表达式似乎适用于ggplot标题.

See if this can give you some idea. Using math expression in base R seems to work for ggplot titles.

library(ggplot2)

df=data.frame(x=1:10, y=rnorm(10))

vn=expression(paste(pH[10]," inicial"))
ggplot(df, aes(x,y))+geom_point()+ ggtitle(vn)

这篇关于在图表(ggplot2)中用另一个文件的标签下标标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆