Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use alpha values provided in data

Tags:

r

ggplot2

alpha

I would like to use the explicit values for the alpha level.

head(D)

    x  y group  alpha
  1 1 18     A   0.40   <~~~~
  2 2 18     A   0.44
  3 3 18     A   0.47
  4 1 18     A   0.51
  5 2 21     B   0.55
  6 3 21     B   0.58
  ...

However, ggplot is scaling the alpha levels. I can override this using scale_alpha_continuous(range = range(D$alpha)), but this becomes a nuisance when creating the graph programmatically.

Is there a direct way to tell ggplot NOT to scale alpha? (instead of telling it what range to scale to)

enter image description here

Reproducible Exmple

library(ggplot)
library(gridExtra)
(D <- data.frame(x=rep(1:3, 4), y=rep((6:8)*3, each=4), group=rep(c("A","B", "C"), each=4),  alpha=round(seq(.4, .8, length.out=12), 2)))

P <- ggplot(data=D, aes(x=x, y=y, alpha=alpha)) + geom_bar(stat="identity", fill="blue") + theme(legend.position="bottom") + facet_grid(group ~. )

### Adding  scale_alpha_continuous
P.manually_scaled <- P + scale_alpha_continuous(range=range(D$alpha))

grid.arrange( P + ggtitle("INCORRECT")
             , P.manually_scaled + ggtitle("CORRECT")
             , ncol=2)
like image 983
Ricardo Saporta Avatar asked Mar 14 '14 15:03

Ricardo Saporta


People also ask

How do you use alpha value?

To get α subtract your confidence level from 1. For example, if you want to be 95 percent confident that your analysis is correct, the alpha level would be 1 – . 95 = 5 percent, assuming you had a one tailed test. For two-tailed tests, divide the alpha level by 2.

What does alpha mean in data?

Before you run any statistical test, you must first determine your alpha level, which is also called the “significance level.” By definition, the alpha level is the probability of rejecting the null hypothesis when the null hypothesis is true. Translation: It's the probability of making a wrong decision.

What alpha value should I use?

The alpha value, or the threshold for statistical significance, is arbitrary – which value you use depends on your field of study. In most cases, researchers use an alpha of 0.05, which means that there is a less than 5% chance that the data being tested could have occurred under the null hypothesis.

What is a good alpha value in research?

Researchers who analyze data within the framework of null hypothesis significance testing must choose a critical “alpha” level, α, to use as a cutoff for deciding whether a given set of data demonstrates the presence of a particular effect. In most fields, α = 0.05 has traditionally been used as the standard cutoff.


1 Answers

If you have actual alpha, color, ..., values then you should use ..identity() scales. This will tell ggplot() to assign alpha values as they are in your data frame and not to scale them.

ggplot(data=D, aes(x=x, y=y, alpha=alpha)) + 
         geom_bar(stat="identity", fill="blue") + 
         facet_grid(group ~. ) +
         scale_alpha_identity()
like image 182
Didzis Elferts Avatar answered Sep 28 '22 15:09

Didzis Elferts