首页 > 解决方案 > 如何更改数据标签的颜色

问题描述

我需要在基础 R 中将数据标签的颜色更改为白色。这可能吗?

 stemdata <- structure(list( #had to round some nums below for 100% bar

 A = c(3, 20, 77), 
 B = c(6, 19, 75),
 C = c(13,13, 74),
 D = c( 13, 19, 68), 
 E = c( 3, 10, 87),
 F = c(6, 16, 78),
 G = c(3, 9, 88)), 

 .Names = c("Extent to which tour was useful",
        "Food, travel, accommodations, and procedures",
         "Travel itinerary and dates",
        "Location of the STEM Tour stops",
         "Interactions with presenters/guides",
         "Duration of each STEM Tour stop",
        "Overall quality of the STEM Tour"
         ), 
 class = "data.frame", 
 row.names = c(NA, -3L)) #4L=number of numbers in each letter vector#

 attach(stemdata) 
 print(stemdata)
 par(mar=c(0, 20, 1, 2.1)) # this sets margins to allow long labels
 barplot(as.matrix(stemdata), 

    beside = F, ylim = range(0, 10), xlim = range(0, 100),
    horiz = T, col=colors,  main="N=29", 
    border=F, las=1, xaxt='n', width = 0.95)

 legend(18,9,  legend=c("Medium","High", "Very High"),                                                                                                                                                                                                                                                                
   fill=colors, horiz = T, bty='n')



text(3.5, 0.7, "7%")
text(15, 0.7, "17%")
text(62, 0.7, "76%")

text(7, 2, "14%")
text(19, 2, "10%")
text(62, 2, "76%")

text(7, 3.2, "14%")
text(22.5, 3.2, "17%")
text(65.5, 3.2, "69%")

text(8, 4.4, "10%")
text(55, 4.4, "86%")

text(3.5, 5.6, "7%")
text(15, 5.6, "17%")
text(62, 5.6, "76%")

text(9, 6.9, "10%")
text(55, 6.9, "86%")

我希望能够添加白色数据标签,而无需使用附加包。非常感谢您提供的任何帮助。非常感谢!

标签: r

解决方案


推荐阅读