1
votes

I have a CSV which has following data:

 Hybrid    ON   OFF Model
1  1.022 1.033 0.939   283
2  0.988 1.016 1.068   283
3  1.012 0.958 1.872   283
4  1.073 5.476 0.907   283
5  1.054 0.952 0.902   283
6  0.992 0.941 0.908   283

I am trying to create a dot plot with something like this image.

enter image description here

Basically red green and blue are hybrid, on and off respectively, and on x-axis they are grouped on the 'Model'. I am familiar with creating simple plots using plot() but I have been reading some tutorial that this could be achieved using ggplot and melt..which looks a bit advanced. Appreciate if someone can provide some indicators. I have tried to create levels for different config after loading the csv:

load <- read.csv("combined_temp.csv", sep="," , header=TRUE)    

df <- data.frame(Config= rep(c("Hybrid", "ON", "OFF")))

I want use ggplot after this but not sure how to do that.. even not sure if I am doing the replication right. Sorry I am extremely new to R.

1
For some inspiration on a compareble problem, see this answer - Jaap
I am sure there is a much simpler way to solve this. Anyone? - Ad_noob

1 Answers

0
votes

The first step is to reshape your data into long format, after that you can make such a plot easily with ggplot2:

library(reshape2)
dfl <- melt(df, id = "Model")

library(ggplot2)
ggplot(dfl, aes(x = factor(Model), y = value)) +
  geom_point(aes(color = variable), shape = 1, size = 4, position = position_dodge(width = 0.4)) +
  theme_bw()

this results in the following plot:

enter image description here


For illustrative reasons, I have expanded and changed the data.

Used data:

df <- structure(list(Hybrid = c(1.022, 0.988, 1.012, 1.073, 1.054, 0.992, 2.022, 1.988, 2.012, 2.073, 2.054, 1.992), 
                     ON = c(1.033, 1.016, 0.958, 3.476, 0.952, 0.941, 2.033, 2.016, 1.958, 3.476, 1.952, 1.941),
                     OFF = c(0.939, 1.068, 1.872, 0.907, 0.902, 0.908, 2.939, 1.068, 1.872, 2.907, 2.902, 2.908),
                     Model = c(283L, 283L, 283L, 283L, 283L, 283L, 382L, 382L, 382L, 382L, 382L, 382L)),
                .Names = c("Hybrid", "ON", "OFF", "Model"), class = "data.frame", row.names = c(NA, -12L))