在 R 中使用 csv 的对数刻度直方图
Histogram with log scale using csv in R
我正在尝试创建一个与此
相同的 histogram
我的 csv
文件包含 2 个 columns
,名为 Value 和 Count。我发现了类似的 posts 但我无法获得如上图所附的结果。我的问题是 y 轴没有像上图那样的值。另外,如何设置 x-axis
以从列 Value 中获取值?请你帮助我好吗?这是代码:
test_csv = read.csv("dir/k.csv")
plot(k$Count, log="y", type='h', lwd=10, lend=2)
这是我的数据:
test_csv = dput(k)
structure(list(Value = 1:101, Count = c(8512998L, 2524797L, 408468L,
141472L, 72906L, 43135L, 29530L, 21288L, 16890L, 13181L, 10935L,
8941L, 7883L, 6677L, 5995L, 5259L, 4802L, 4124L, 3912L, 3411L,
3228L, 2761L, 2690L, 2335L, 2200L, 1878L, 1792L, 1586L, 1520L,
1219L, 1232L, 1087L, 1027L, 895L, 845L, 761L, 781L, 712L, 676L,
614L, 578L, 506L, 476L, 452L, 438L, 394L, 373L, 345L, 325L, 348L,
320L, 257L, 260L, 219L, 227L, 213L, 177L, 182L, 170L, 151L, 135L,
127L, 118L, 116L, 123L, 96L, 115L, 69L, 72L, 78L, 70L, 63L, 60L,
64L, 67L, 50L, 63L, 64L, 63L, 49L, 53L, 45L, 48L, 48L, 40L, 56L,
28L, 44L, 40L, 32L, 22L, 18L, 30L, 18L, 23L, 15L, 27L, 22L, 22L,
21L, 10L)), class = "data.frame", row.names = c(NA, -101L))
最后,这是我制作的
对于 scales
和 ggplot2
这样的软件包,您可以试试这个:
ggplot(k,aes(y=Count,x=Value))+geom_histogram(stat="identity")+scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(10^.x)))
您可以随意使用 xlab
和 ylab
函数更改轴标签
我正在尝试创建一个与此
histogram
我的 csv
文件包含 2 个 columns
,名为 Value 和 Count。我发现了类似的 posts 但我无法获得如上图所附的结果。我的问题是 y 轴没有像上图那样的值。另外,如何设置 x-axis
以从列 Value 中获取值?请你帮助我好吗?这是代码:
test_csv = read.csv("dir/k.csv")
plot(k$Count, log="y", type='h', lwd=10, lend=2)
这是我的数据:
test_csv = dput(k)
structure(list(Value = 1:101, Count = c(8512998L, 2524797L, 408468L,
141472L, 72906L, 43135L, 29530L, 21288L, 16890L, 13181L, 10935L,
8941L, 7883L, 6677L, 5995L, 5259L, 4802L, 4124L, 3912L, 3411L,
3228L, 2761L, 2690L, 2335L, 2200L, 1878L, 1792L, 1586L, 1520L,
1219L, 1232L, 1087L, 1027L, 895L, 845L, 761L, 781L, 712L, 676L,
614L, 578L, 506L, 476L, 452L, 438L, 394L, 373L, 345L, 325L, 348L,
320L, 257L, 260L, 219L, 227L, 213L, 177L, 182L, 170L, 151L, 135L,
127L, 118L, 116L, 123L, 96L, 115L, 69L, 72L, 78L, 70L, 63L, 60L,
64L, 67L, 50L, 63L, 64L, 63L, 49L, 53L, 45L, 48L, 48L, 40L, 56L,
28L, 44L, 40L, 32L, 22L, 18L, 30L, 18L, 23L, 15L, 27L, 22L, 22L,
21L, 10L)), class = "data.frame", row.names = c(NA, -101L))
最后,这是我制作的
对于 scales
和 ggplot2
这样的软件包,您可以试试这个:
ggplot(k,aes(y=Count,x=Value))+geom_histogram(stat="identity")+scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(10^.x)))
您可以随意使用 xlab
和 ylab
函数更改轴标签