1

Hi My data (data_long) looks like this:

 genes  sample  value   Group Type
 A1 O7high  6796.448    G0   A
 AA O7high  4997.250    G0   A
 A3 O7high  9477.100    G0   A
 A4 O7high  6083.558    G0   A   
 A1 08low   075.364     G0   B
 AA 08low   13066.130   G0   B

p <- ggplot(data_long, aes(x=sample, y=value,group=genes,color=Group))  + 
  geom_tile(aes(fill = as.factor(Type),color = NA,y = 7000), height = Inf, alpha = 0.5) +
  geom_line(aes(linetype=Group,color=Group, size=Group)) + 
  stat_summary(aes(group = -1), fun=median, geom='line',size=2, color='orange') + 
  theme_classic() + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))+
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
  scale_y_sqrt()+
  scale_colour_manual(values=c("black","blue"))+
  scale_size_manual(values=c(0.3,1.5))+
  scale_linetype_manual(values=c("dashed", "solid"))+
  theme_classic()

p + theme_bw() +
  theme(panel.grid = element_blank(),
        panel.border = element_blank())

I have used the above code to plot the median line as well as to highlight some of the genes of my interest. Everything works fine but When seeing the plot there are these vertical grey lines (Separating each sample?) I am not sure how to remove those lines. I want the geom_tile for the same type to be without any lines. Please let me know how to remove those lines

enter image description here

camille
  • 16,432
  • 18
  • 38
  • 60
Biofreek
  • 39
  • 5
  • 2
    Your example isn't reproducible. However, you might find the lines disappear if you take `color=Group` out of the first `aes` call inside the call to `ggplot`and only use it inside the `aes` call in `geom_line` – Allan Cameron Oct 12 '21 at 22:47
  • 1
    Your plotting code is missing a call to `geom_tile()` (or similar), which would draw the background colours, so it's impossible to see what is going wrong without the code that produced this figure. – phalteman Oct 12 '21 at 23:01
  • My bad! I have edited the example. Thanks for point out – Biofreek Oct 12 '21 at 23:24
  • Thanks, Jared. I have one new field -Type. It is used for generating tiles `fill = as.factor(Type)`. I am having trouble removing the vertical lines across tiles – Biofreek Oct 12 '21 at 23:35
  • 1
    Not specific to the question, but your code will be much easier to read (for yourself and others) if you use some spaces, especially when you'd otherwise have a string of several functions added together on a single line. You've also assigned premade themes 3 times, potentially overriding at least some of your manual theme settings. If the theme settings aren't actually related to the question, though, you might as well remove them for the sake of keeping the question minimal ([mcve])—same goes for scales – camille Oct 12 '21 at 23:43

1 Answers1

0

Thanks for updating your question with the required info. Perhaps you can remove the grey lines by moving color = NA outside aes(), e.g.

library(tidyverse)
data_long <- read.table(text = "genes  sample  value   Group Type
A1 O7med  6796.448    G0   A
AA O7med  4997.250    G0   A
A3 O7high  9477.100    G0   A
A4 O7high  6083.558    G0   A   
A1 08low   075.364     G0   B
AA 08low   13066.130   G0   B", header = TRUE)

p <- ggplot(data_long, aes(x=sample, y=value,group=genes,color=Group))  + 
  geom_tile(aes(fill = as.factor(Type), y = 7000), color = NA, height = Inf, alpha = 0.5) +
  geom_line(aes(linetype=Group,color=Group, size=Group)) + 
  stat_summary(aes(group = -1), fun=median, geom='line',size=2, color='orange') + 
  theme_classic() + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))+
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
  scale_y_sqrt()+
  scale_colour_manual(values=c("black","blue"))+
  scale_size_manual(values=c(0.3,1.5))+
  scale_linetype_manual(values=c("dashed", "solid"))

p + theme_bw() +
  theme(panel.grid = element_blank(),
        panel.border = element_blank())

Created on 2021-10-13 by the reprex package (v2.0.1)

Does that work on your actual dataset?

jared_mamrot
  • 22,354
  • 4
  • 21
  • 46
  • Thanks, Jared. it works exactly the way I wanted – Biofreek Oct 13 '21 at 15:42
  • You're welcome - thanks for adding the necessary details to your post - if this answer has solved your problem, please consider [accepting it](https://stackoverflow.com/help/someone-answers) – jared_mamrot Oct 13 '21 at 21:56