0

I'm plotting a graph in R using ggplot2. It's a lined graph with points for every observations, the points represent p-values. Three of them are not significant, and I want these points to show up differently (any other shape/color, doesn't matter). Now I'm not sure how to do this.

I've tried scale_shape_manual(values = c(valueA, valueB, valueC)) and scale_color_manual, but I don't get any results. No error messages either, just nothing happens.

Can anyone help?

ggplot(data = dataframe) + 
  geom_line(aes(x=Time, y=Treatment),  color="#00AFBB")+
 geom_point(aes(x=Time, y=Treatment)) +
  scale_y_reverse()+
    scale_x_continuous( breaks = c(1, 2, 3, 4, 5, 6,7,8,9,10,11,12,13,14,15,16,17,18,19,20))

Thanks!

--

Edit: here a reproducible sample (I hope it works?):

A <- c(1,2,3,4,5)
B <- c(1,2,3,4,5)
df <- data.frame(cbind(A, B))
dilly
  • 63
  • 1
  • 7
  • What value in your dataframe indicates whether or not they are significant? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Jun 02 '21 at 17:03
  • The p-values that are bigger than 0.05 are not significant (for example, 0.053520717). I thought I could do something like x>0.05 = red or something – dilly Jun 02 '21 at 17:06
  • I'll try to add a reproducible sample! – dilly Jun 02 '21 at 17:06
  • Your plot code uses a dataframe called `dataframe` that has columns called `Time` and `Treatment`. The sample data is called `df` and only has columns called `A` and `B`. How are they related? – Jon Spring Jun 02 '21 at 17:42

1 Answers1

1

Here's an example, hopefully helpful. I use scale_color_identity and scale_shape_identity because my data (in this case created through the if_else statements) specifies the literal color/shape I want to use.

Time <- c(1,2,3,4,5)
Treatment <- c(1,2,3,4,5)
df <- data.frame(Time = 1:5, Treatment = 1:5)

ggplot(data = df) + 
  geom_line(aes(x=Time, y=Treatment), color = "#00AFBB") +
  geom_point(aes(x=Time, y=Treatment,  
                 shape = if_else(Treatment < 5, 18, 1),  
                 color = if_else(Treatment < 5, "#00AFBB", "black")), size = 4) +
  scale_y_reverse()+
  scale_x_continuous( breaks = 1:20) +
  scale_color_identity() +
  scale_shape_identity()

enter image description here

Jon Spring
  • 55,165
  • 4
  • 35
  • 53