3

I have the following data imported in R from a text file with df = as.data.frame(read.table("file.txt"))

    AED round2 round3
1  0.00  0.020  0.022
2  0.02  0.041  0.045
3  0.04  0.066  0.073
4  0.06  0.094  0.103
5  0.08  0.120  0.132
6  0.10  0.146  0.160
7  0.12  0.171  0.189
8  0.14  0.195  0.215
9  0.16  0.218  0.241
10 0.18  0.240  0.265

Now I want to make a simple dot plot of the values from round2 on y-axis vs. AED on x-axis and in the same graphic a second plot for the values of round3 with a different color with ticks of 0.10 interval.

The best solution I came up with until now is qplot(data=df, AED, round2, color="Round2")

But I need some help how to get the second plot in there and how to change the spacing on the axis from 0.25 to 0.10

I read the tutorial here http://www.cookbook-r.com/Graphs/Axes_%28ggplot2%29/ but they are using different data layout with the groups specified explicitly for each row and not by a simple header.

So how can I get this to make 1 plot for each column? (in one graphic)

zx8754
  • 52,746
  • 12
  • 114
  • 209
voiDnyx
  • 975
  • 1
  • 11
  • 24

2 Answers2

2

Try this:

library(ggplot2)
library(tidyr)

# wide to long format
plotDat <- gather(df, Group, myValue, -1)

# plot
ggplot(plotDat, aes(AED, myValue, col = Group)) +
  geom_point() +
  #fix breaks on axis
  scale_x_continuous(breaks = seq(0, 1, 0.1)) +
  scale_y_continuous(breaks = seq(0, 1, 0.1))

enter image description here

zx8754
  • 52,746
  • 12
  • 114
  • 209
0

Here is a solution using dotchart in base graphicsdotplot with two variables

# Make data frame with a factor and two numeric ranges 
Dt <- data.frame(Item = c("a","b","c","d","e","f"), 
                 V1 = seq(1:6), 
                 V2 = seq(1:6)+.2
                 )

# Plot dotchart for first range
dotchart(Dt$V1,
         labels = Dt$Item, 
         pch = 20,
         pt.cex = 2 ,
         xlim = c(0, max(Dt$V2)),
         col = "blue")

# Allow over-plotting
par(new = TRUE)

# Plot dotchart for second range
dotchart(Dt$V2,
     labels = Dt$Item, 
     pch = 15, 
     pt.cex = 2, 
     xlim = c(0, max(Dt$V2)),
     col = "black"
     )

# Add a legend for each range
legend("bottomright", 
   c("V1","V2"),
   pch = c(20,15),
   col = c("blue","black") 
   )
Markm0705
  • 1,340
  • 1
  • 13
  • 31