Hi,
I appreciate if someone can help in arranging one legend (Shape) at the bottom (Fraction) while one remain at the left.
Thank you
my data and code are here:
data <- read.table(text = "proxy Longitude Latitude fraction variable values count Shape
A 845076.8133 7952906.509 ground_floor server 5 2 3
B 628213.526 4922672.854 second_floor server 3 38 6
C -7893548.463 4138071.5 ground_floor server 9 1 20
G -7669834.187 2590343.455 ground_floor server2 12 1 1
E -10699192.16 7126643.172 ground_floor server 14 1 19
F 64789.72751 4435533.366 ground_floor server 16 2 9
G -338124.8274 4561495.29 third_floor server 15 5 8
H -2531015.267 7503498.634 fourth_floor server 22.1 1 64
I 975533.7618 5024220.061 third_floor server 24.8 36 5
j -7920520.004 4804023.573 ground_floor server3 27.5 5 22
k -6697659.731 4128488.631 ground_floor server 30.2 9 35
D -6852811.697 3505961.577 ground_floor server2 32.9 6 2
G 1444849.581 5678072.381 ground_floor server3 35.6 6 4
B 2561971.64 4329459.255 fifth_floor server3 38.3 43 10
F -1225583.899 7057209.131 ground_floor server4 41 4 18
D 571523.8736 4726135.588 ground_floor server3 43.7 3 7
", header = TRUE)
library(tidyverse)
library(ggnewscale)
data <- data %>%
mutate(variable = factor(variable),
fraction = factor(fraction))
ggplot(data) +
aes(x = Latitude, y = Longitude) +
geom_point(aes(shape=variable),color = "red", fill = "white", size = 4) +
scale_shape_manual(name = "Shape", values = unique(data$variable)) +
ggnewscale::new_scale("shape")+
geom_point(aes(shape=fraction),color = "black", fill = "white", size = 4) +
scale_shape_manual(name = "Fraction", values = unique(data$fraction)) +
theme(legend.key = element_rect(fill = "white", color = "black"))