library(tidyverse)
library(png)
png = readPNG("GsWv1.png", native = FALSE, info = FALSE)
a1 = (2882-191)/27
b1 = 191-a1
a2 = (2916-230)/27
b2 = 230-a2
ncol1 = (1:28)*a1+b1
ncol2 = (1:28)*a2+b2
nrows = 9:413
rows=9:413
scale=98/300
fbar = function(png, rows, col){
col = round(round(png[rows,col,1], 2)+
round(png[rows,col,2], 2)+
round(png[rows,col,3], 2), 2)
sum(col>0.5 & col <1.5)
}
df = tibble(data = 1:28) %>%
mutate(redval = map(data, ~fbar(png, rows, .x*a1+b1)),
greenval = map(data, ~fbar(png, rows, .x*a2+b2))) %>%
unnest(c(redval, greenval)) %>%
mutate(data = data %>% factor(), #Adjust this mutation
redval=redval*scale,
greenval = greenval*scale) %>%
pivot_longer(redval:greenval) %>%
mutate(name = name %>% fct_inorder())
df %>% ggplot(aes(data, value, fill=name))+
geom_bar(stat="identity", position=position_dodge())
注意!这仅适用于 png 大小的 998x132 点!您可能需要稍微调整这些值。在那里做,我写了评论。
更新 1
哎呀!我在我的cmets中犯了一个小错误。 png 文件大小必须恰好为 2,956 x 418 像素。以防万一,我附上从下面这张图表中读取的数据。
structure(list(data = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L,
4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 10L, 10L, 11L, 11L,
12L, 12L, 13L, 13L, 14L, 14L, 15L, 15L, 16L, 16L, 17L, 17L, 18L,
18L, 19L, 19L, 20L, 20L, 21L, 21L, 22L, 22L, 23L, 23L, 24L, 24L,
25L, 25L, 26L, 26L, 27L, 27L, 28L, 28L), .Label = c("1", "2",
"3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14",
"15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25",
"26", "27", "28"), class = "factor"), name = structure(c(1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("redval", "greenval"), class = "factor"),
value = c(19.6, 17.64, 32.0133333333333, 33.32, 18.2933333333333,
16.66, 43.12, 37.8933333333333, 47.04, 35.9333333333333,
48.3466666666667, 42.7933333333333, 20.9066666666667, 15.3533333333333,
70.8866666666667, 29.0733333333333, 11.4333333333333, 6.86,
114.66, 114.986666666667, 48.3466666666667, 35.9333333333333,
90.16, 84.28, 18.62, 20.9066666666667, 23.52, 30.7066666666667,
42.7933333333333, 45.4066666666667, 41.8133333333333, 13.0666666666667,
46.06, 50.96, 38.5466666666667, 25.8066666666667, 46.7133333333333,
20.9066666666667, 32.0133333333333, 26.7866666666667, 83.9533333333333,
83.6266666666667, 61.74, 63.0466666666667, 10.4533333333333,
6.53333333333333, 85.26, 24.5, 40.8333333333333, 37.24, 2.94,
2.94, 19.6, 16.66, 25.1533333333333, 19.6)), row.names = c(NA,
-56L), class = c("tbl_df", "tbl", "data.frame"))
下面我还附上我从中读取值的原始图片。