I am trying to generate a dotplot that shows changes in virus infection over time in multiple individuals. More than one virus can be detected, and I want each virus to have its own color in the dotplot. Where it gets complicated is when an individual has more than one virus at the same timepoint. I would like to display this data by showing the 2nd virus as a semicircle on top of the first virus present. I have been playing around with this and it looks like adding a 2nd geom_point layer in ggplot2 with a unicode character for a semicircle (e.g. “u25D7”) is one of the easier ways to do this. However, I’m running into two issues.
First: I can’t get the unicode characters to display in any ggplot. I get the hollow square of failure instead.
Second: I need to suppress one of the result categories (“Neg” in “Res2”) so that semicircles are only imposed at dots where two viruses are detected simultaneously.
Any advice would be greatly appreciated! I’m running R v 4.4.0 with English_United States.utf8 on Windows 10.
Some example data and code:
library(ggplot2)
library(ggthemes)
library(tidyverse)
library(dplyr)
AnimalID<-c("A","A","A","A","A","B","B","B","B","B","C","C","C","C","C")
Week<-c(1,2,3,4,5,1,2,3,4,5,1,2,3,4,5)
Res1<-c("HV1","HV1","Neg","HV2","Neg","Neg","HV2","HV1","HV1","HV1","HV1","HV1","HV2","Neg","HV1")
Res2<-c("HV2","Neg","Neg","Neg","Neg","Neg","Neg","HV2","Neg","Neg","Neg","HV2","Neg","Neg","Neg")
AllHV<-c("HV1 and HV2","HV1","Neg","HV2","Neg","Neg","HV2","HV1 and HV2","HV1","HV1","HV1","HV1 and HV2","HV2","Neg","HV1")
db<-data.frame(AnimalID,Week,Res1,Res2,AllHV)
Exgraph<-
ggplot(db,aes(x= Week, y=AnimalID, color=Res1)) +
geom_point(size=3,shape=16) +
theme_tufte() +
ggtitle("HV Shedding Patterns") +
xlab("Study Week") +
ylab("Animal ID") +
theme(axis.line = element_line(colour = "black")) +
theme(plot.title = element_text(face = "bold",size=18)) +
theme(axis.text = element_text(size = 10)) +
theme(axis.title = element_text(face = "bold",size = 14)) +
theme(legend.title = element_text(size = 14, face = "bold"),legend.text = element_text(size = 11)) +
labs(color='HV')+
geom_point(aes(x= Week, y=AnimalID, color=Res2)) ## this is where I'd be adding the unicode +
scale_color_manual(values=c("green","blue","grey80"))
Exgraph`
TurtleyAwesome is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.