创建图形 p <- ggplot(featureImportance, aes(x = reorder(Feature, Importance), y =…
- User
创建图形
p <- ggplot(featureImportance, aes(x = reorder(Feature, Importance), y = Importance, fill = Category)) + geom_bar(stat = "identity", width = 0.6, color = "black") + scale_fill_manual(values = colors) + # 手动指定填充颜色 geom_text(aes(label = Significance), hjust = -0.5, size = 8) + coord_flip() + theme_light(base_size = 20) + theme( axis.title.x = element_text(size = 15, color = "black", face = "plain", family = "Times New Roman"), axis.title.y = element_blank(), axis.text.x = element_text(size = 15, color = "black", face = "plain", family = "Times New Roman"), axis.text.y = element_text(size = 15, color = "black", face = "plain", family = "Times New Roman"), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), legend.position = c(0.8, 0.2), # 图例 legend.title = element_text(size = 12, face = "plain", family = "Times New Roman"), # 设置图例标题的样式 legend.text = element_text(size = 12, face = "plain", family = "Times New Roman"), # 设置图例文本的样式 legend.key.size = unit(0.8, "cm") # 设置图例符号的大小 ) 怎么让柱子的外框线更粗一点
- Assistant
要让柱子的外框线更粗,你可以在
geom_bar()中添加size参数,来设置条形的边框线宽度。你可以这样做:rp <- ggplot(featureImportance, aes(x = reorder(Feature, Importance), y = Importance, fill = Category)) + geom_bar(stat = "identity", width = 0.6, color = "black", size = 1.5) + # 这里调整了size参数 scale_fill_manual(values = colors) + # 手动指定填充颜色 geom_text(aes(label = Significance), hjust = -0.5, size = 8) + coord_flip() + theme_light(base_size = 20) + theme( axis.title.x = element_text(size = 15, color = "black", face = "plain", family = "Times New Roman"), axis.title.y = element_blank(), axis.text.x = element_text(size = 15, color = "black", face = "plain", family = "Times New Roman"), axis.text.y = element_text(size = 15, color = "black", face = "plain", family = "Times New Roman"), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), legend.position = c(0.8, 0.2), legend.title = element_text(size = 12, face = "plain", family = "Times New Roman"), legend.text = element_text(size = 12, face = "plain", family = "Times New Roman"), legend.key.size = unit(0.8, "cm") )