Highlight specific bars depending of a factor
1
0
Entering edit mode
9.8 years ago
viniciushs88 ▴ 50

I would like highlight some specifics bars in my barplot depending of a factor.

In this example:

dat <- read.table(text = "sam_760 sam_1541 sam_723 sam_727
1 19.5 12 8.7 5.77
3 3.84 0 5.8 7.62", header = TRUE)
barplot(as.matrix(dat))

The sam_760 bar have a factor == 84, the sam_1541 == 25, sam_723 == 12 and sam_727 == 15. I thought in some color scale from grey to red highlighting the sam_760 in example, however would be nice other scale suggestions.

Anyway, Thank you very much!

R color-scale barplot • 3.7k views
ADD COMMENT
0
Entering edit mode
9.8 years ago

Using border you can set an extra layer of color to your barplots.

I would suggest, adding another row of factors for the variables and plotting using ggplot library, which gives much more control over the plots.

Check geom_bar for doing this, in conjugation with melt function from the library reshape.

ADD COMMENT

Login before adding your answer.

Traffic: 3231 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6