I am trying to recreate this plot but I am having an issue with ggplot not liking the negative numbers in the data frame by the looks of the error message? Error: colours encodes as numbers must be positive
. Does anyone know what its issue is? These are very large data frames but I wouldn't have thought that would have been an issue?
## Load packages
library(tidyverse)
require(data.table)
## Read in data frames
m1<-fread("m1.csv", header = F)
m2<-fread("m2.csv", header = F)
L<-fread("l.csv", header = F)
LP<-fread("LP.csv", header = F)
## Get rate by taking m1 from m2
rate<-m1[1,]-m2[1,] ### subtract p1 rate from p2
## Transpose the data frame
t_rate <- transpose(rate)
## Create row ID's to merge data frames
L$row_num <- seq.int(nrow(L))
t_rate$row_num <- seq.int(nrow(t_rate))
all<-merge(L, t_rate, by = "row_num") ## merge the dataframes based on their ID
## Get rid of ID now we don't need it
all$row_num=NULL
## Plot the graph
ggplot(all,x=all$V1.x,y=all$V2,col=all$V1.y)+
geom_point(data=all,x=all$V1.x,y=all$V2,col=all$V1.y,size=0.1)+
geom_point(data=LP,x=LP$V1,y=LP$V2,size=1)
### Data (all)
structure(list(V1.x = c(163.75, 164.25, 164.75, 165.25, 165.75,
166.25), V2 = c(-75.25, -75.25, -75.25, -75.25, -75.25, -75.25
), V1.y = c(1.55995, 1.56093, 1.56237, 1.56545, 1.56764, 1.56827
)), class = c("data.table", "data.frame"), row.names = c(NA,
-6L), .internal.selfref = <pointer: 0x7f9bd4811ae0>)
## Data (LP)
structure(list(V1 = c(169.7, 147.93, 150.01, 146.71, 147.31,
-63.26), V2 = c(-46.47, -42.344, -36.59, -38.64, -43.3, 44.739
)), row.names = c(NA, -6L), class = c("data.table", "data.frame"
), .internal.selfref = <pointer: 0x7f9bd4811ae0>)
The issue is that you did not map on aesthetics but instead pass vectors to arguments. When doing so you have to pass color names or codes or a positive number to the color
argument.
But to fix your issue you could simply map on aesthetics like so:
library(ggplot2)
ggplot(all, aes(x = V1.x, y = V2)) +
geom_point(aes(color = V1.y), size = 0.1) +
geom_point(data = LP, aes(x = V1, y = V2), size = 1)