Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
';at';和';标签';长度不同,13!=10 R中的错误_R_Plot_Bar Chart_Devtools_Plotrix - Fatal编程技术网

';at';和';标签';长度不同,13!=10 R中的错误

';at';和';标签';长度不同,13!=10 R中的错误,r,plot,bar-chart,devtools,plotrix,R,Plot,Bar Chart,Devtools,Plotrix,我有一个数据帧,df,看起来是这样的: a b c d e f g h i j k l m 1a 4 4 3 4 3 4 3 4.0 4.0 4 4 4 3.9 1b 9 9 9 9 9 9 9 8.1 8.8 9 9 9 8.5 1c 8 8 9 8 9 8 8 8.0 9.0

我有一个数据帧,df,看起来是这样的:

      a   b   c   d   e   f   g    h     i    j   k   l    m
1a    4   4   3   4   3   4   3   4.0   4.0   4   4   4   3.9
1b    9   9   9   9   9   9   9   8.1   8.8   9   9   9   8.5
1c    8   8   9   8   9   8   8   8.0   9.0   8   9   8   8.3
1d    8   8   8   9   8   9   8   8.0   8.0   8   8   8   8.5
1e    4   4   4   4   4   4   4   4.0   4.0   4   4   4   4.0
2a    3   4   3   4   3   4   3   4.0   3.0   4   3   4   3.8
2b    8   8   8   8   8   8   8   8.0   8.0   8   8   8   8.0
2c    8   8   8   8   8   8   8   9.0   8.0   9   8   8   8.3
2d    8   9   8   8   8   9   8   9.0   8.0   9   8   9   8.0
2e    4   3   4   3   4   4   4   4.0   4.0   4   4   3   3.9
我正在使用
plotrix
devtools
软件包,并且已经安装了这两个软件包,而且
barp2
功能如下:

# install the packages and load the barp2 function
install.packages('plotrix')
install.packages('devtools')
install_url("http://cran.r-project.org/src/contrib/Archive/plotrix/plotrix_3.5-2.tar.gz")
source_gist("https://gist.github.com/tleja/8592929")

# load the packages
library(plotrix)
library(devtools)
par(mar = c(5, 4, 4, 6))
barp2(df, pch=t(c(0:4, 7:14)), names.arg=rownames(df), legend.lab=colnames(df),
    ylab="y label", main="main")
barp2(t(df), pch=t(c(0:4, 7:11)), names.arg=rownames(df), legend.lab=colnames(df),
ylab="y label", main="main")
我正在使用的修改代码(
barp2
)可用

我试图在上面提供的数据框中绘制数据,如下所示:

# install the packages and load the barp2 function
install.packages('plotrix')
install.packages('devtools')
install_url("http://cran.r-project.org/src/contrib/Archive/plotrix/plotrix_3.5-2.tar.gz")
source_gist("https://gist.github.com/tleja/8592929")

# load the packages
library(plotrix)
library(devtools)
par(mar = c(5, 4, 4, 6))
barp2(df, pch=t(c(0:4, 7:14)), names.arg=rownames(df), legend.lab=colnames(df),
    ylab="y label", main="main")
barp2(t(df), pch=t(c(0:4, 7:11)), names.arg=rownames(df), legend.lab=colnames(df),
ylab="y label", main="main")
我正在使用,来填充绘图栏

我希望df的行名是x轴标签,df的colname是一个图例

然而,我不断地发现这个错误:

Error in axis(1, at = x, labels = names.arg, cex.axis = cex.axis) : 
    'at' and 'labels' lengths differ, 13 != 10
Error in seq.default(x1[frect] + xinc[frect]/2, x2[frect] - xinc[frect]/2,  : 
    wrong sign in 'by' argument
我知道这是因为
rownames(df)
的长度为10,
colnames(df)
的长度为13(显然不相等),但我不确定如何解决这个问题,以便数据框中的数据显示在条形图中

或者如果我使用
t(df)
交换列和行,如下所示:

# install the packages and load the barp2 function
install.packages('plotrix')
install.packages('devtools')
install_url("http://cran.r-project.org/src/contrib/Archive/plotrix/plotrix_3.5-2.tar.gz")
source_gist("https://gist.github.com/tleja/8592929")

# load the packages
library(plotrix)
library(devtools)
par(mar = c(5, 4, 4, 6))
barp2(df, pch=t(c(0:4, 7:14)), names.arg=rownames(df), legend.lab=colnames(df),
    ylab="y label", main="main")
barp2(t(df), pch=t(c(0:4, 7:11)), names.arg=rownames(df), legend.lab=colnames(df),
ylab="y label", main="main")
我得到这个错误:

Error in axis(1, at = x, labels = names.arg, cex.axis = cex.axis) : 
    'at' and 'labels' lengths differ, 13 != 10
Error in seq.default(x1[frect] + xinc[frect]/2, x2[frect] - xinc[frect]/2,  : 
    wrong sign in 'by' argument
我不知道这个错误是什么意思,也不知道我为什么会得到它

很抱歉,我不能提供它应该是什么样子的图像,但希望你能得到它的基本概念


任何帮助都将不胜感激。

t()
关于pch的参数似乎有误。@IShouldBuyABoat-即使我删除了
pch
上的
t()
,我仍然会得到同样的错误。我包含了
t()
,因为数据必须以矩阵格式提供,以指定不同的符号。矩阵的列应符合
pch
参数的顺序。正如有人说过的。