小编cyr*_*jan的帖子

如何下标x轴刻度标签

我用下面的脚本生成了这个图. 在此输入图像描述 但我怎么能下标PM10中的"10",SO2中的"2"和NO2中的"2"?

我试过了levels(df$variable) <- c("PM[10]","SO[2]", "NO", "NO[2]"),但没办法.

有人可以帮忙吗?谢谢!

variable <- c("PM10","SO2","NO","NO2")
coef <- c(10,20,30,40)
coef_lb <- c(-5,10,23,27)
coef_ub <- c(20,39,39,50)

df <- as.data.frame(cbind(variable, as.numeric(coef),as.numeric(coef_lb),as.numeric(coef_ub)))


df$variable <- factor(df$variable,levels=c("PM10","SO2","NO","NO2"))
levels(df$variable) <- c("PM[10]","SO[2]", "NO", "NO[2]")

library(ggplot2)
#ggplot 95%CI
BWplot <- ggplot(data=df,aes(x=variable,y=coef))
BWplot <- BWplot + geom_pointrange(aes(ymin=coef_lb,ymax=coef_ub))
BWplot <- BWplot + geom_point() 
BWplot <- BWplot + scale_y_continuous(limits=c(-110, 110),breaks=seq(-100, 100, by = 20))
BWplot <- BWplot + xlab("Air pollutant") 
BWplot <- BWplot + ylab("Mean change") 
BWplot <- BWplot + geom_hline(yintercept=0,alpha=0.5)
BWplot
Run Code Online (Sandbox Code Playgroud)

r ggplot2 axis-labels

10
推荐指数
1
解决办法
3845
查看次数

如何在ggplot的facet_grid函数中应用下标

我想用ggplot来绘制空气污染物与出生体重变化(95%CI)之间关系的结果.

我的数据格式是这样的

variable    exposure period      coef    coef_lb      coef_ub
PM10        entire pregnancy    -27.6      -49.2         -3.8
SO2         entire pregnancy       40       14.2         62.8
NO          entire pregnancy      -26        -44         -6.4
NO2         entire pregnancy        0        -20           19
PM10        trimester1          -29.4      -49.4           -8
SO2         trimester1             12         -9         31.8
NO          trimester1            5.2      -15.2         28.2
NO2         trimester1           -2.2        -23         16.6
PM10        trimester2          -11.8      -35.2         11.2
SO2         trimester2           26.2          2         51.4
NO          trimester2          -10.8      -35.2         12.4
NO2         trimester2           -7.4      -27.8         14.6
PM10        trimester3            6.2      -17.6         28.2
SO2         trimester3            0.6 …
Run Code Online (Sandbox Code Playgroud)

r subscript ggplot2

5
推荐指数
1
解决办法
2780
查看次数

在bash中按名称(匹配模式)提取列

Coding,Value,Meaning,54-1.0,54-2.0,431-2.0,212-0.0,212-1.0
1,1,Yes,0.4,0.3,0.7,0.1,0.6
2,0,Other job (free text entry),0,0.7,0.3,0.7,0.8
2,1,Managers and Senior Officials,0.5,0.2,0.4,0.7,0.7
2,11,Corporate Managers,0.1,0.7,0.4,0.2,0.4
2,111,Corporate Managers And Senior Officials,0,0.8,0.8,0.4,0.8
2,1111,Senior officials in national government,0.9,0.6,0.4,0.2,0.9
2,1111001,AM (National Assembly),0.8,0.3,0.2,0,0.2
2,1111002,Ambassador (Foreign and Commonwealth Office),0.9,0.9,0.7,0.1,0.2
2,1111003,Band 0 (Health and Safety Executive),0.6,0.4,0,0.4,0.8
2,1111004,Band 1B (Meteorological Office),0.6,0.1,0.6,1,0.8
Run Code Online (Sandbox Code Playgroud)

我有一个像上面这样的 csv.gz 文件。我想按匹配某些字符串的名称提取列,例如,列名称匹配“54-”和“212-”。

我找到了如下解决方案,但我想知道是否可以对其进行修改,以便它可以提取与字符串列表中的任何元素匹配的列,例如“含义”、“54-”、“212-”。

zcat test.csv.gz |awk -F, 'NR==1{for(i=1;i<=NF;i++)if($i~/54-/)f[n++]=i}{for(i=0;i<n;i++)printf"%s%s",i?" ":"",$f[i];print""}' 
Run Code Online (Sandbox Code Playgroud)

我还想将其保存到 csv.gz 文件中。但是通过> outputfile.csv在最后添加,我不能用逗号分隔。我想知道我应该把OFS=","这个命令放在哪里?

示例输出如下(在 csv.gz 文件中)

Meaning,54-1.0,54-2.0,212-0.0,212-1.0
Yes,0.4,0.3,0.1,0.6
Other job (free text entry),0,0.7,0.7,0.8
Managers and Senior Officials,0.5,0.2,0.7,0.7
Corporate Managers,0.1,0.7,0.2,0.4
Corporate Managers And Senior Officials,0,0.8,0.4,0.8 …
Run Code Online (Sandbox Code Playgroud)

csv awk extract multiple-columns

0
推荐指数
1
解决办法
71
查看次数

标签 统计

ggplot2 ×2

r ×2

awk ×1

axis-labels ×1

csv ×1

extract ×1

multiple-columns ×1

subscript ×1