问题描述
我想用 R 绘制一个时间线,其中的时间段很容易识别,我可以在其中个性化可视化:
I want to plot a timeline with R where the periods are easily identifiable, in which I could personalize the visualization of:
- 句点
- 句点框"的颜色
- 线条(颜色、位置)
- 文本的位置并将其放入框"中
- 轴(大小,颜色,选择重点)
- 活动日期
- 等
我使用时间轴库,但是我找不到如何对其进行个性化.有什么建议或其他图书馆吗?
I use timeline library, however I couldn't find how to personalized it. Any suggestions or other libraries?
输出如下:
我的 R 代码是这样的:
My R code is this:
require(timeline)
f <- "~/Documents/periods.csv"
crono <- read.delim(f, header=TRUE)
f <- "~/Documents/events.csv"
events <- read.delim(f, header=TRUE)
draw <- function() {
timeline(crono, events,
text.size = 8,
text.color = "black",
num.label.steps = 2,
event.label.method = 1,
event.text.size = 7,
event.label = '',
event.line = TRUE,
event.above = FALSE)
}
png("~/Documents/Timeline.png", width = 1200,
height = 800, units = "px", bg = "transparent", res = NA)
draw()
dev.off()
这是我的数据.一系列时间段:
Here there is my data. Series of periods of time:
Name Group Start_year End_year
First long period long 1800 1899
Second period short 1870 1910
Another long period long 1900 1990
More events on period time short 1965 1985
以及同时发生的一些事件:
and some events during the same time:
Event year
Person 1 was born 1870
Person 1 first novel 1895
Build the new building 1905
Death person 1 1930
renovation building 1950
collection 1970
推荐答案
使用 vistime
包,您可以个性化框的颜色(如果您在数据框中添加颜色"列或告诉vistime
与 col.colors ='yourColourColumnName'
,您可以添加工具提示并分发到组中 (col.groups =
).
Using package vistime
, you could personalize colors of the boxes (if you add "color" column in your data frame or tell vistime
with col.colors ='yourColourColumnName'
, you can add tooltips and distribute into groups (col.groups =
).
您可以生成 plotly-Timelines、highcharter-Timelines 或 ggplot2-Timelines,它们都是可个性化的.
You can produce plotly-Timelines, highcharter-Timelines or ggplot2-Timelines, all of them are personalizable.
install.packages("vistime")
library(vistime)
crono <- read.csv(text="Name,Group,start_year,end_year
First long period,long,1800-01-01,1899-12-31
Second period,short,1870-01-01,1910-12-31
Another long period,long,1900-01-01,1990-12-31
More events on period time,short,1965-01-01,1985-12-31")
events <- read.csv(text="Name,start_year
Person 1 was born,1870-01-01
Person 1 first novel,1895-01-01
Build the new building,1905-01-01
Death person 1,1930-01-01
renovation building,1950-01-01
collection,1970-01-01")
events$end_year <- NA
events$Group <- "Events"
# or gg_vistime, or hc_vistime
vistime(rbind(crono, events),
col.start = "start_year",
col.end = "end_year",
col.event = "Name",
col.group = "Group")
关于个性化的更多信息:https://shosaco.github.io/vistime/
More info about personalization: https://shosaco.github.io/vistime/
这篇关于如何使用 R 个性化时间线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!