我想知道仅使用 ggplot 是否可以将不同的主题分配给不同的方面。
这个问题关系到这一个,我觉得通过@baptiste提供的解决方案应该是最好的一个。
使用他的代码,我获得了以下图:
有了这个数据:
RIM BlackBerry Pearl Palm Treo 700p Motorola Q Nokia 9300 Sony Ericsson M600i Sidekick3 id
Compact 6.9 5.7 6.7 4.5 5.1 3.6 Compact
Quality of display 7.5 6.3 7.3 5.1 6.2 3.8 Quality of display
Push email availability 8.2 7.4 6.4 6.4 6.0 4.5 Push email availability
Brand image 8.6 8.5 7.2 6.5 4.5 3.0 Brand image
Comfortable to call 7.4 6.9 6.1 4.2 5.2 3.1 Comfortable to call
High prestige 7.2 6.9 6.8 5.5 4.0 1.2 High prestige
Run Code Online (Sandbox Code Playgroud)
而这段代码:
data_sub = melt(data_sub)
# Set id as factor
data_sub$id = factor(data_sub$id, levels=unique(data_sub$id))
# Add empty levels to reach 9 levels
levels(data_sub$id) = c(levels(data_sub$id), c((1 + length(unique(data_sub$id))):9))
ggplot(data_sub, aes(x=variable, y=value, fill = "same_for_all") ) +
geom_bar(stat = "identity") +
facet_wrap(~ id, ncol = 3, drop = FALSE) +
scale_fill_manual(values = globals$graphics$color$palette2) +
coord_flip() +
theme(axis.ticks.x = element_blank(),
axis.text.x = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid = element_blank(),
legend.position = "none")
Run Code Online (Sandbox Code Playgroud)
是否可以使用theme()将隐藏与图 7、8 和 9 相关的所有元素,同时仍返回 ggplot 对象的 a ?