0
votes

I am attempting to make a boxplot on RStudio with the variables 'Control' and 'Experimental', but each control needs to have 2 subsets of data ('Day' and 'Night'). So essentially I want 4 separate box-and-whisker plots on one plot (if that makes any sense at all?).

I have two separate data frames with the headings 'Day', 'Night', and 'Hue', so would need day and night on the x-axis, and hue on the y-axis. I have tried re-arranging my data frame to have 2 columns ('Time' eg day/night, and 'Hue') but ggplot2 doesnt seem to like this either.

I literally can't get these plots to work at all,so any help would be appreciated!

Thanks in advance!

ETA: Actual Data:

1 Group Hue

2 1 0.26

3 1 0.39

4 1 0.23

5 1 0.24

6 1 0.05

7 1 0.71

8 1 0.59

9 1 0.78

10 1 0.63

11 1 1.09

12 1 0.18

13 1 0.83

14 1 0.20

15 1 0.15

16 1 0.17

17 1 0.24

18 1 0.42

19 1 0.38

20 1 0.61

21 1 0.49

22 1 0.46

23 1 0.50

24 1 0.41

25 1 0.23

26 1 0.11

27 1 0.47

28 1 0.15

29 1 0.40

30 1 0.31

31 1 0.34

32 2 1.37

33 2 0.21

4 2 0.48

35 2 0.10

36 2 0.82

37 2 0.63

38 2 0.48

39 2 0.70 40 2 0.68 41 2 0.76 42 2 0.52 43 2 0.68 44 2 2.62 45 2 0.13 46 2 0.40 47 2 0.39 48 2 0.41 49 2 0.50 50 2 0.66 51 2 0.56 52 2 0.58 53 2 0.17 54 2 0.47 55 2 0.31 56 2 0.39 57 2 0.49 58 2 0.38 59 2 0.48 60 2 0.47 61 2 0.40 62 3 1.16 63 3 0.30 64 3 0.40 65 3 0.53 66 3 0.30 67 3 0.39 68 3 0.38 69 3 0.36 70 3 0.35 71 3 0.34 72 3 0.39 73 3 0.47 74 3 0.37 75 3 0.52 76 3 0.52 77 3 0.50 78 3 0.48 79 3 0.55 80 3 0.62 81 3 0.59 82 3 0.26 83 3 0.39 84 3 0.23 85 3 0.24 86 3 0.47 87 3 0.71 88 3 0.59 89 3 0.78 90 3 0.48 91 3 0.37 92 4 1.43 93 4 0.46 94 4 1.26 95 4 2.65 96 4 1.43 97 4 0.38 98 4 0.35 99 4 0.59 100 4 1.38 101 4 0.51 102 4 1.12 103 4 0.42 104 4 0.43 105 4 0.36 106 4 0.62 107 4 1.60 108 4 0.58 109 4 1.57 110 4 0.43 111 4 1.19 112 4 0.77 113 4 1.37 114 4 2.21 115 4 1.48 116 4 0.20 117 4 2.82 118 4 0.63 119 4 0.48 120 4 2.58 121 4 0.43

Whereas R is putting this data into my boxplot: Group Hue

1 Control Day 12.43503

2 Control Day 15.50208

3 Control Day 10.55415

4 Control Day 14.55953

5 Control Day 14.81230

6 Control Day 17.17195

7 Control Day 16.72419

8 Control Day 12.82169

9 Control Day 12.71106

10 Control Day 12.39931

11 Control Day 16.41781

12 Control Day 17.60299

13 Control Day 14.94367

14 Control Day 19.76444

15 Control Day 18.16637

16 Control Day 13.53893

17 Control Day 12.13074

18 Control Day 13.79023

19 Control Day 11.37030

20 Control Day 18.51498

21 Control Day 16.43221

22 Control Day 10.87997

23 Control Day 17.54314

24 Control Day 17.46402

25 Control Day 19.95249

26 Control Day 14.50452

27 Control Day 18.43108

28 Control Day 13.29810

29 Control Day 10.05007

30 Control Day 13.79817

31 Control Night 18.61311

32 Control Night 11.38397

33 Control Night 14.95923

34 Control Night 14.06546 35 Control Night 12.49782 36 Control Night 12.32807 37 Control Night 14.51005 38 Control Night 12.62860 39 Control Night 19.34517 40 Control Night 18.93672 41 Control Night 12.43503 42 Control Night 15.50208 43 Control Night 10.55415 44 Control Night 14.55953 45 Control Night 14.81230 46 Control Night 17.17195 47 Control Night 16.72419 48 Control Night 12.82169 49 Control Night 12.71106 50 Control Night 12.39931 51 Control Night 16.41781 52 Control Night 17.60299 53 Control Night 14.94367 54 Control Night 19.76444 55 Control Night 18.16637 56 Control Night 13.53893 57 Control Night 12.13074 58 Control Night 13.79023 59 Control Night 11.37030 60 Control Night 18.51498 61 Experiment Day 16.43221 62 Experiment Day 10.87997 63 Experiment Day 17.54314 64 Experiment Day 17.46402 65 Experiment Day 19.95249 66 Experiment Day 14.50452 67 Experiment Day 18.43108 68 Experiment Day 13.29810 69 Experiment Day 10.05007 70 Experiment Day 13.79817 71 Experiment Day 18.61311 72 Experiment Day 11.38397 73 Experiment Day 14.95923 74 Experiment Day 14.06546 75 Experiment Day 12.49782 76 Experiment Day 12.32807 77 Experiment Day 14.51005 78 Experiment Day 12.62860 79 Experiment Day 19.34517 80 Experiment Day 18.93672 81 Experiment Day 12.43503 82 Experiment Day 15.50208 83 Experiment Day 10.55415 84 Experiment Day 14.55953 85 Experiment Day 14.81230 86 Experiment Day 17.17195 87 Experiment Day 16.72419 88 Experiment Day 12.82169 89 Experiment Day 12.71106 90 Experiment Day 12.39931 91 Experiment Night 16.41781 92 Experiment Night 17.60299 93 Experiment Night 14.94367 94 Experiment Night 19.76444 95 Experiment Night 18.16637 96 Experiment Night 13.53893 97 Experiment Night 12.13074 98 Experiment Night 13.79023 99 Experiment Night 11.37030 100 Experiment Night 18.51498 101 Experiment Night 16.43221 102 Experiment Night 10.87997 103 Experiment Night 17.54314 104 Experiment Night 17.46402 105 Experiment Night 19.95249 106 Experiment Night 14.50452 107 Experiment Night 18.43108 108 Experiment Night 13.29810 109 Experiment Night 10.05007 110 Experiment Night 13.79817 111 Experiment Night 18.61311 112 Experiment Night 11.38397 113 Experiment Night 14.95923 114 Experiment Night 14.06546 115 Experiment Night 12.49782 116 Experiment Night 12.32807 117 Experiment Night 14.51005 118 Experiment Night 12.62860 119 Experiment Night 19.34517 120 Experiment Night 18.93672

1
I think it's better if you can provide a working example, or have snippets of your code. That being said, from what you are describing, I'd recommend merging the datasets into one and use grouping, coloring and facets to achieve your plot.Amir

1 Answers

1
votes

As commented, I would recommend merging your two dataframes, so you have two columns: Group (including Control Day, Control Night, Experiment Day, Experiment Night), and Hue.

So your data would be structured like the output from this (example data only):

data<-data.frame(Group=rep(c(rep("Control Day",10),rep("Control Night",10),
                  rep("Experiment Day",10),rep("Experiment Night",10))),
                 Hue=runif(40,10,20))

Then your plot should work by:

plot<-ggplot(data,aes(x=factor(Group),y=Hue))+
  geom_boxplot()
plot