如何使用R对时间线进行个性化设置?
我想用R绘制一个时间轴,在这个时间轴中,周期很容易识别,我可以个性化地显示:如何使用R对时间线进行个性化设置?,r,timeline,R,Timeline,我想用R绘制一个时间轴,在这个时间轴中,周期很容易识别,我可以个性化地显示: 时期 “框”的颜色 线条(颜色、位置) 文本的位置并将其放入“框” 轴(大小、颜色,选择要强调的轴) 活动日期 等 我使用时间线库,但我找不到如何个性化它。有什么建议或其他图书馆吗 输出如下所示: 我的R代码是: require(timeline) f <- "~/Documents/periods.csv" crono <- read.delim(f, header=TRUE) f <- "~
- 时期
- “框”的颜色
- 线条(颜色、位置)
- 文本的位置并将其放入“框”
- 轴(大小、颜色,选择要强调的轴)
- 活动日期
- 等
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()
以及同时发生的一些事件:
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
使用package
vistime
,您可以对方框的颜色进行个性化设置(如果您在数据框中添加“颜色”列,或者使用col.colors='YourColumnName'
告诉vistime
,您可以添加工具提示并将其分发到组中(col.groups=
)
您可以生成plotly时间表、highcharter时间表或ggplot2时间表,所有这些都是个性化的
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")
install.packages(“vistime”)
图书馆(vistime)
crono使用timeline绘制和个性化很容易,因为timeline库是使用ggplot2机制构建的。因此,例如,如果您想让您的timeline具有Economist主题,可以执行以下操作(使用您提供的代码):
库(ggthemes)
图书馆(GG2)
p看到这里了吗?是的,可能会有帮助!谢谢!但是它并没有告诉我们如何及时处理长时间的事件:如何策划和个性化
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")
library(ggthemes)
library(ggplot2)
p <- 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)
p + + theme_wsj() + scale_colour_wsj("colors6", "")