我对使用R进行编码非常陌生。我正在处理相对简单的数据,只是其中的大量数据。我正在尝试根据发现这些鲸鱼的年份创建时间表。因此,我只有两个变量(年份和种类)和151个观测值。在这个时间轴上总共有25个物种可以绘图,我在下面提供了我的数据的一个小例子。
year species
1792 Megaptera novaeangliae
1792 Physeter macrocephalus
1793 Physeter macrocephalus
1832 Physeter macrocephalus
1833 Physeter macrocephalus
我已经尝试使用timelineS和timelineG以及vistime创建时间线。 TimelineG接近创建我想要的东西,但似乎没有绘制任何内容。代码如下:
timelineG(t8, start="year", end="year", names="species")
我只是被困住了。我确实有看到该物种的月份和日期,因此我可以根据需要添加回来。预先感谢您的指导。
[ggplot
的示例:
library(tidyverse)
df <- tibble::tribble(
~year, ~species,
1792L, "Megaptera novaeangliae",
1792L, "Physeter macrocephalus",
1793L, "Physeter macrocephalus",
1832L, "Physeter macrocephalus",
1833L, "Physeter macrocephalu"
)
df %>%
ggplot(aes(x = year, y = species)) +
geom_point()
或使用timelineG
功能:
library(timelineS)
df %>%
group_by(species) %>%
summarise(start = min(year),
end = max(year)) %>%
timelineG(start = "start", end = "end", names = "species")
或使用timelineg这样,
dta <- data.frame(species = c('Megaptera novaeangliae','Physeter macrocephalus',
'Physeter macrocephalus','Physeter macrocephalus',
'Physeter macrocephalus'),
year = c(1792,1792,1793,1832,1833))
#str(dta)
dta$year <- as.Date(ISOdate(dta$year, 1, 1)) # assuming beginning of year for year
# str(dta)
timelineS(dta, main = "BGoodwin's species example")