r


R adding layers to a ggplot plot with vectors of different length


I research this problem, and all tricks fail here. I am trying to build ROC curve in ggplot. Different models of machine learning return a different length of observations vectors. My goal is to gather them in one plot, color and put legend.
It is easy when all your data has the same X axis length - (number of observations). All x and y are in a range of [0 to 1]. A problem is a different number of observations. I'd like to avoid interpolating and coercing vectors to the same length because each observation carries important information.
So far I figured out that the best approach would be put new layers of lines on the same plot.
Maybe other types of plot? or specialized plots from other packages.
Please help. Thanks!
ggplot(vector_1, aes(x, y ) ) + geom_line() + ???? new layers ???
My goal is to obtain a plot like this but with more lines:
Here is vector1 - 34 observations:
vector_1_x:
0
0.02325581
0.02325581
0.04651163
0.04651163
0.06976744
0.09302326
0.11627907
0.13953488
0.1627907
0.18604651
0.20930233
0.23255814
0.25581395
0.27906977
0.30232558
0.3255814
0.37209302
0.39534884
0.41860465
0.44186047
0.46511628
0.48837209
0.51162791
0.53488372
0.62790698
0.65116279
0.74418605
0.76744186
0.86046512
0.90697674
0.93023256
0.97674419
1
vector_1_y:
0
0
0.1666667
0.1666667
0.3333333
0.3333333
0.3333333
0.3333333
0.3333333
0.3333333
0.3333333
0.3333333
0.3333333
0.3333333
0.3333333
0.3333333
0.5
0.5
0.5
0.6666667
0.6666667
0.6666667
0.6666667
0.6666667
0.6666667
0.6666667
0.8333333
0.8333333
0.8333333
1
1
1
1
1
Here is vector2 - 50 observations:
vector_2_x:
0
0
0.02325581
0.04651163
0.04651163
0.06976744
0.09302326
0.11627907
0.13953488
0.1627907
0.18604651
0.20930233
0.23255814
0.25581395
0.25581395
0.27906977
0.30232558
0.3255814
0.34883721
0.37209302
0.39534884
0.39534884
0.41860465
0.44186047
0.46511628
0.48837209
0.51162791
0.51162791
0.53488372
0.55813953
0.58139535
0.60465116
0.62790698
0.65116279
0.65116279
0.6744186
0.69767442
0.72093023
0.74418605
0.76744186
0.79069767
0.81395349
0.8372093
0.86046512
0.88372093
0.90697674
0.93023256
0.95348837
0.97674419
1
vector_2_x:
0
0.1666667
0.1666667
0.1666667
0.3333333
0.3333333
0.3333333
0.3333333
0.3333333
0.3333333
0.3333333
0.3333333
0.3333333
0.3333333
0.5
0.5
0.5
0.5
0.5
0.5
0.5
0.6666667
0.6666667
0.6666667
0.6666667
0.6666667
0.6666667
0.8333333
0.8333333
0.8333333
0.8333333
0.8333333
0.8333333
0.8333333
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
Put vector_1 and vector_2 into their own data frames like so:
df1 <- data.frame(x = vector_1_x, y = vector_1_y)
df2 <- data.frame(x = vector_2_x, y = vector_2_y)
Then you can specify a different data.frame for each ggplot layer:
ggplot() +
geom_line(data = df1, aes(vector_1_x, vector_1_y), colour = "red") +
geom_line(data = df2, aes(vector_2_x, vector_2_y), colour = "green")
Update
What I wrote above originally is okay for a few lines but it will be much cleaner to put all the vectors in their own data.frame with an indicator variable stating which line it belongs to. This would look something like:
x y vector
1 1 "line1"
2 3 "line1"
3 6 "line1"
... ... ...
1 8 "line2"
2 6 "line2"
3 2 "line2"
... ... ...
Then in you can have a single ggplot layer:
ggplot(data = df) + geom_line(aes(x, y, colour = vector))

Related Links

How does glmnet handle NA values?
R POSIX %H:%M:%S Time Average
Variable that updates conditional value
R code to analyze genotyping data.
Running a Powershell script from R using system2() rather than system()?
Enabling vignette compression for R CMD build in RStudio
What is the NULL environment?
Simple function does not work for `dcast` - reshape2
Use to 2 parameters … in one function
Randomly Assign Integers in R within groups without replacement
why function rbind.data.frame behave different in do.call
Is there in R something like the “here document” in bash?
How to index character vector in file.path in R
R Shiny: Error in max - min : non-numeric argument to binary operator
using a loop in R to output many files
Run R interactively from Rscript

Categories

HOME
salt
dc.js
error-reporting
luajit
data-structures
gmail-api
cycle
remote-desktop
transition
spark-java
publish-subscribe
sinatra
phpdocumentor2
symfony-cmf
angular2-components
draw.io
xodus
sat
revel
coordinate-systems
json-deserialization
wsl
anonymous-class
sling
bdd
stacked-chart
chrome-web-store
registration
arquillian-drone
mapper
big-theta
kendo-tabstrip
vue-component
exist-db
incredibuild
mkmapview
ternary-search-tree
html-parsing
pg-search
google-font-api
glassfish-4.1.1
aws-mobilehub
django-1.8
shortcut
edifact
npm-start
semantic-ui-css
github-desktop
infinidb
jquery.panzoom
gwt-2.7
buildpath
docker-toolbox
xtragrid
dvd
weblogic9.x
resume-download
lejos-nxj
office-2013
composition
openoffice-base
mysql-fabric
document-management
digital-filter
palm-os
websocket++
gwt-super-dev-mode
reactive-extensions-js
flash-cs3
wcf-behaviour
datetimeoffset
copycopter
file-ownership
cruisecontrol
autoresizingmask
sites
hextiles
capifony
mdbg
listfield
ghci
opensoundcontrol
dedicated-hosting
mediacenter
bitblt
sandy3d
innovation
automated-deploy

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App