0

I have a Plot in R, that shows several variables on the x-axis. On the y-axis, there are different departments. Each department has its own ability to save data (the variables on the x-axis). If a variable can be saved by one of the department (TRUE), the department gets a point at the intersection of the two axis. It works for every single variable, that is TRUE in any of the departments. But the problem is, if a variable is not TRUE in any of the departments, the variable is not showing in the plot at all. So my question is: is there is any way to show all the variables on my x axis, even if they are not relevant for the plot? I already added a "Initial department", where every variable is true, but that is only be an interim solution.

The code for plotting is this:

tdf2 <- df2 %>% gather(Abteilungen, value, -names) 
p <- tdf2 %>% filter(value==TRUE) %>%
  ggplot(aes(names, Abteilungen, col=Abteilungen)) + geom_point() +
  scale_y_discrete(limits = rev(levels(factor(tdf2$Abteilungen)))) +
  theme(axis.text.x = element_text(angle = 90)) +
  xlab("Erfasste Parameter") +
  ylab("Betrachtete Abteilungen") + 
  labs(title = "Gießener Abteilungen im Vergleich: Möglichkeit der strukturierten Erfassung von Parametern")
print(p)
DodgeRand
  • 1
  • 1
  • Hi DodgeRand. If you add a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) its way easier for others to find a solution to your problem. That way you can help others to help you! – dario Feb 24 '20 at 11:16
  • you're removing `FALSE` values with `filter(value==TRUE)`- that may be the reason why you don't see them in the plot. by the way, a shorter way to filter for value == TRUE would be simply `filter(value)` – tjebo Feb 24 '20 at 11:18
  • 2
    P.S. your graph may be easier to read when flipping it around using `+ coord_flip()` – tjebo Feb 24 '20 at 11:23
  • Hi, first plz give us an example to play with. Second what if you plot different point shapes for TRUE and FALSE? i.e. don't filter(value == TRUE) and try ggplot(aes( x = names, y = Abteilungen, colour = Abteilungen, shape = value)). – ktyagi Feb 24 '20 at 12:15
  • First of all, thank you guys. @ktyagi your solution works! On default, the false values will be shown as triangles. To change the icon (for example to an empty ring) i had to add ...+ scale_shape_manual(values=c(1,19)) + ... – DodgeRand Feb 24 '20 at 13:41
  • great then shall I write it as an answer? – ktyagi Feb 25 '20 at 18:32

0 Answers0