-1

I have a csv in R which has the following table:

df1 <- data.frame(
        "Pool 1" = c("F1a", "R1a", "F2a", "R2a"),
        "Start Pool 1" = c("10", "20", "25", "35"), 
        "Pool 2" = c("F1b", "R1b", "F2b", "R2b"),
        "Start Pool 2" = c("15", "21", "23", "35"), 
        stringsAsFactors = F,check.names=FALSE)
Pool 1 Start Pool 1 Pool 2 Start Pool 2
F1a 10 F1b 15
R1a 20 R1b 21
F2a 25 F2b 23
R2a 35 R2b 35

I want to create a graph in R which looks like this: Final graph goal

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
mk894
  • 33
  • 7
  • Would you please give more detailed information? For example, can you clarify what you want your `x-axis` to be etc.? – bird May 15 '21 at 10:53

1 Answers1

1

Seems like your labels for Pool 2 is wrong, should be R1b instead

If you don't want to use any package, and have only 2 lines, you can build it up slowly by specifying a blank plot with plot(NULL...) , then you will place one line on y=1, the other on y=2 and add the points, text based on these coordinates:

plot(NULL,xlim=c(10,35),ylim=c(0,3),xaxt="n",yaxt="n",
bty="n",xlab="",ylab="")
abline(h=1:2,col="#c0fefc")
points(x = df1[,"Start Pool 1"], y = rep(2,nrow(df1)),
pch=20,cex=2,col="#77acf1")
text(x = df1[,"Start Pool 1"], y = rep(2.5,nrow(df1)),
labels = df1[,"Pool 1"])
points(x = df1[,"Start Pool 2"], y = rep(1,nrow(df1)),
pch=20,cex=2,col="#77acf1")
text(x = df1[,"Start Pool 2"], y = rep(1.5,nrow(df1)),
labels = df1[,"Pool 2"])
axis(side=2,at=1:2,labels=c("Pool2","Pool1"),las=2,col=NA,col.ticks = 1)

enter image description here

Else use ggplot2 :

df = data.frame(
       label = c(df1[,"Pool 1"],df1[,"Pool 2"]),
       value = c(df1[,"Start Pool 1"],df1[,"Start Pool 2"]),
       pool = rep(c("Pool1","Pool2"),each=nrow(df1))
       )

ggplot(df,aes(x=value,y=pool,label=label)) + 
geom_point(size=4,col="#77acf1") + 
geom_text(nudge_y=0.2) + 
theme_minimal() + 
xlab("") + ylab("") +
theme(panel.grid.major.x = element_blank(),
axis.ticks.x = element_blank(),
axis.text.x = element_blank())

enter image description here

StupidWolf
  • 45,075
  • 17
  • 40
  • 72