【发布时间】:2018-11-22 07:33:44
【问题描述】:
我正在尝试执行以下操作。考虑以下数据集
trends <- c('Virtual Assistant', 'Citizen DS', 'Deep Learning', 'Speech Recognition',
'Handwritten Recognition', 'Machine Translation', 'Chatbots',
'NLP')
impact <- sample(5,8, replace = TRUE)
maturity <- sample(5,8, replace = TRUE)
strategy <- sample(5,8, replace = TRUE)
h <- sample(5,8, replace = TRUE)
df <- data.frame(trends, impact, maturity, strategy, h)
rownames(df) <- df$trends
我正在尝试生成热图。到目前为止还不错。这相对容易。例如我可以使用
dftemp = df[,c("impact", "maturity", "strategy", "h")]
dt2 <- dftemp %>%
rownames_to_column() %>%
gather(colname, value, -rowname)
然后
ggplot(dt2, aes(x = rowname, y = colname, fill = value)) +
geom_tile()
我知道 x 轴上的标签是水平的,但我知道如何解决这个问题。我想要的是根据一个特定的行对 x 轴进行排序。例如,我希望热图与行“影响”(例如)值按升序排列。任何人都可以指出我正确的方向吗? 我应该将 x 转换为一个因子并更改那里的水平吗?
【问题讨论】: