简体   繁体   English

在绘制直方图(如垂直线)时,y轴没有值

[英]y-Axis without values while plotting histogram like vertical lines

I have a data frame ( table1 ) with the following schema: 我有一个数据框( table1 )与以下架构:

> table1

      sides frequency relFrequency
1         1         1          0.1
2         2         3          0.3
3         3         0          0.0
4         4         3          0.3
5         5         1          0.1
6         6         2          0.2

> summary(table1)
        sides    frequency   relFrequency
 Min.   :1.00   n.vars :1       n.vars :1  
 1st Qu.:2.25   n.cases:10      n.cases:1  
 Median :3.50                           
 Mean   :3.50                           
 3rd Qu.:4.75                           
 Max.   :6.00

I want to create a histograme like plot histogram: 我想创建一个像直方图这样的直方图:

plot(table1$sides, table1$relFrequency, type="h")

Unfortunately the y-Axis has no values. 不幸的是,y轴没有值。 I think this is because relFrequency is treated as a factor. 我认为这是因为relFrequency被视为一个因素。 Can I convert the factor somehow to numeric? 我能以某种方式将因子转换为数字吗?

Thank you. 谢谢。

//edit //编辑

> dput(table1)
structure(list(side = c(1, 2, 3, 4, 5, 6), frequency = structure(c(1L, 
3L, 0L, 3L, 1L, 2L), .Dim = 6L, class = "table"), relFrequency = structure(c(0.1, 
0.3, 0, 0.3, 0.1, 0.2), class = "table", .Dim = 6L)), row.names = c(NA, 
6L), class = "data.frame")

> str(table1)
'data.frame':   6 obs. of  3 variables:
 $ side: num  1 2 3 4 5 6
 $ frequency        : 'table' int [1:6(1d)] 1 3 0 3 1 2
 $ relFrequency : 'table' num [1:6(1d)] 0.1 0.3 0 0.3 0.1 0.2

在此输入图像描述

After this, it did work: 在此之后,它确实有效:

table1$frequency <- as.numeric(table1$frequency)
aufgabe1$relFrequency <- as.numeric(table1$frequency)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM