条形图:R中y轴上的希腊字母 [英] Barplot: Greek letters on y axis in R
问题描述
这是我关于条形图的其他问题的后续问题:
我使用以下代码:
#龙卷风图数据<-矩阵(c(-0.02,0.02,-0.01,0.01,-0.03,0.02,-0.01,0.04),ncol = 4)行名(数据)<-c('+ 10%','-10%')列名(数据)<-c('V_bar','alpha','rho','xi')x<-seq(-0.04,0.04,长度= 10)barplot(data [1,],horiz = T,las = 1,xlim = c(-0.04,0.04),xaxt ='n',ylab ='',在旁边= T,col = c('springgreen'))barplot(data [2,],horiz = T,las = 1,xlim = c(-0.04,0.04),xaxt ='n',yaxt ='n',#防止y标签重复打印.在旁边= T,col = c('indianred2'),添加= TRUE)axis(1,at = pretty(x),lab = paste0(pretty(x)* 100,%"),las = TRUE)
要获取希腊字母,我尝试了以下操作:
barplot(数据[2,],horiz = T,las = 1,xlim = c(-0.04,0.04),xaxt ='n',yaxt = c(expression(bar(V)),expression(alpha),expression(rho),expression(xi)),在旁边= T,col = c('indianred2'),添加= TRUE))
和
axis(2,at = c(1:4),lab =表达式(xi〜rho〜alpha〜bar(V)),las = T)
或
axis(2,at = pretty(x),lab = paste0(expression(xi〜rho〜alpha〜bar(V)),las = T))
但是没有成功.现在有人把戏了吗?
注意.我已经看到了以下问题:在轴标题中添加希腊字符但是它专注于标签,而不是y轴值".另外,我尝试了类似在列名称中放入希腊字母的操作没有成功.
如果提供参数 names.arg
,则无需调用 axis
标记条形到 barplot
:
barplot(data [1,],horiz = T,las = 1,xlim = c(-0.04,0.04),xaxt ='n',ylab ='',在旁边= T,col = c('springgreen'),names.arg = c(expression(xi),expression(rho),expression(alpha),expression(bar(V))))
This is a follow-up question to my other question on barplots: Tornado plot in R
I realized the question about getting greek letters on the y-axis needed to be asked as an own question.
The question is: I have the following barplot and need to change the y-axis to respective greek letters (and a V with a bar over).
I use the following code:
# Tornado plot
data <- matrix(c(-0.02,0.02,-0.01,0.01,-0.03,0.02,-0.01,0.04), ncol = 4)
rownames(data) <- c('+10%','-10%')
colnames(data) <- c('V_bar', 'alpha', 'rho','xi')
x <- seq(-0.04,0.04, length=10)
barplot(data[1,], horiz = T, las=1, xlim = c(-0.04,0.04), xaxt='n', ylab='',
beside=T, col=c('springgreen'))
barplot(data[2,], horiz = T, las=1, xlim = c(-0.04,0.04), xaxt='n',
yaxt='n', #To prevent double printing of y-labels.
beside=T, col=c('indianred2'), add = TRUE)
axis(1, at=pretty(x), lab=paste0(pretty(x) * 100," %"), las=TRUE)
To get the greek letters I have tried the following:
barplot(data[2,], horiz = T, las=1, xlim = c(-0.04,0.04), xaxt='n',
yaxt= c(expression(bar(V)), expression(alpha),expression(rho), expression(xi)),
beside=T, col=c('indianred2'), add = TRUE))
and
axis(2, at=c(1:4), lab = expression(xi ~ rho ~ alpha ~ bar(V)), las=T)
or
axis(2, at=pretty(x), lab = paste0(expression(xi ~ rho ~ alpha ~ bar(V)), las=T))
But no success. Anyone now the trick?
Note. I have seen this question: Adding greek character to axis title But it focuses on the labels, not the y-axis "values". Also, I have tried something like Putting greek letters in column names with no success.
There's no need to call axis
for labeling of the bars if you provide the argument names.arg
to barplot
:
barplot(data[1,], horiz = T, las=1, xlim = c(-0.04,0.04), xaxt='n', ylab='',
beside=T, col=c('springgreen'),
names.arg=c(expression(xi),expression(rho), expression(alpha), expression(bar(V))))
这篇关于条形图:R中y轴上的希腊字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!