我目前正在使用R中的Alluvial包来创建可视化.
这是我的数据集:
https://app.box.com/s/6qju42u0cg1cmrnhyhyzmjtp59wnsn3q
这是我的代码:
alluvial(fb_ad_3d[,2:3], freq=fb_ad_3d$freq,
col = ifelse( fb_ad_3d$Response == "Yes", "skyblue1",
"darkorchid1" ),xw = 0.2,alpha = 0.6,
gap.width=0.2,cex = 1.1, cex.axis = 1.5)
Run Code Online (Sandbox Code Playgroud)
这是可视化:
我真的不喜欢两件事:
流连接器边缘的锯齿形图案
左侧的某些类别(农业,事件,电子,电信)已被压缩,使其不合格.
有什么方法可以改善这种可视化并使其美观?
这是数据集:https : //www.dropbox.com/s/mrlfnh6e2ww1xwd/home.csv?dl=0
这是我的代码:
hom <- read.csv(file.choose(),header=TRUE)
home.melt <- melt(hom, id.vars='home')
ggplot(home.melt,
aes(x = reorder(home, value), y = value,
fill=forcats::fct_rev(variable))) +
geom_bar(stat = "identity",width = 0.8) + coord_flip() +
theme_minimal(base_size=10) +
labs(title="Home time",
subtitle="By matches",
x="Home",
y="time (minutes)",
fill=" ")
Run Code Online (Sandbox Code Playgroud)
这是输出:
如您所见,它不是按降序排列的。
我有以下数据集:
https://app.box.com/s/au58xaw60r1hyeek5cua6q20byumgvmj
我想根据一天中的时间创建密度图。这是我到目前为止所做的:
library("ggplot2")
library("scales")
library("lubridate")
timestamp_df$timestamp_time <- format(ymd_hms(hn_tweets$timestamp), "%H:%M:%S")
ggplot(timestamp_df, aes(timestamp_time)) +
geom_density(aes(fill = ..count..)) +
scale_x_datetime(breaks = date_breaks("2 hours"),labels=date_format("%H:%M"))
Run Code Online (Sandbox Code Playgroud)
它给出以下错误:
Error: Invalid input: time_trans works with objects of class POSIXct only
如果我将其转换为POSIXct,它会将日期添加到数据中。
更新1
以下数据转换为“NA”
timestamp_df$timestamp_time <- as.POSIXct(timestamp_df$timestamp_time, format = "%H:%M%:%S", tz = "UTC"
Run Code Online (Sandbox Code Playgroud)
更新2