我有一個寬資料框,如下所示:
> dput(Birthrate)
structure(list(`Country Name` = "United States", `Country Code` = "USA",
`Indicator Name` = "Fertility rate, total (births per woman)",
`Indicator Code` = "SP.DYN.TFRT.IN", `1960` = 3.654, `1961` = 3.62,
`1962` = 3.461, `1963` = 3.319, `1964` = 3.19, `1965` = 2.913,
`1966` = 2.721, `1967` = 2.558, `1968` = 2.464, `1969` = 2.456,
`1970` = 2.48, `1971` = 2.266, `1972` = 2.01, `1973` = 1.879,
`1974` = 1.835, `1975` = 1.774, `1976` = 1.738, `1977` = 1.79,
`1978` = 1.76, `1979` = 1.808, `1980` = 1.8395, `1981` = 1.812,
我想像這樣按年份繪制出生率(y 軸)
,但是我的資料格式很寬。有沒有一種簡單的方法可以像在影像中一樣繪制出生率?
uj5u.com熱心網友回復:
這有效:
br <- unlist(BirthRate[-(1:4)])
plot(as.numeric(names(br)), br)
...但是可能值得回到上游并弄清楚如何將您的資料轉換為長格式... tidyversedplyr::pivot_longer()功能可能是您所需要的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/426666.html
標籤:r
