How to add text below legend manually in ggplot? - r

I have noted that different versions of this question have been asked throughout the years. However, I cannot find a solution that fits my script. I have seen several functions, but they do not quite do the thing.
Please find my data w1 and w2 below.
I want to add text manually below the legend as demonstrated below.
I use the following:
# My script
df <- data.frame(x = as.factor(c(w1$ny_stadie, w2$ny_stadie)),
y = c(w1$n.fjernet, w2$n.fjernet),
f = rep(c("N+", "N0"), c(nrow(w1), nrow(w2))))
df <- df[!is.na(df$x),]
ggplot(df) +
geom_boxplot(aes(x, y, fill = f, colour = f), outlier.alpha = 0, position = position_dodge(width = 0.78)) +
scale_x_discrete(name = "", label=c("X I\nn=113","X II\nn=102","X III\nn=115","X IV\nn=302")) +
scale_y_continuous(name="X", breaks=seq(0,130,10), limits=c(-5,130)) +
stat_boxplot(aes(x, y, colour = f), geom = "errorbar", width = 0.3,position = position_dodge(0.7753), size=1) +
geom_point(aes(x, y, fill = f, colour = f), size = 3, shape = 21, position = position_jitterdodge(), alpha=0.7) +
scale_fill_manual(values = c("#edf1f9", "#fcebeb"), name = "X",
labels = c("X", "X")) +
scale_colour_manual(values = c("#1C73C2", "red"), name = "X",
labels = c("X", "X"))
theme(axis.text.x = element_text(color = "grey20", size = 14), axis.title.x = element_text(color = "grey20", size = 14, face="bold", margin=margin(t=12))) +
theme(axis.text.y = element_text(color = "grey20", size = 11), axis.title.y = element_text(color = "grey20", size = 14, face="bold", margin=margin(r=12))) +
theme(legend.key = element_rect(fill = "white")) +
theme(legend.text=element_text(size=12)) + theme(legend.title=element_text(size=14))
And my data
# My Data
w1 <- structure(list(ny_stadie = structure(c(1, 1, 4, 4, 1, 3, 1, 4,
3, 2, 2, 3, 4, 4, 4, 2, 4, 4, 3, 4, 2, 4, 4, 4, 4, 1, 4, 4, 4,
2, 1, 2, 2, 3, 1, 4, 3, 1, 3, 1, 4, 4, 2, 1, 4, 1, 4, 2, 4, 2
), class = "AsIs"), n.fjernet = c(25L, 3L, 27L, 22L, 18L, 9L,
6L, 5L, 25L, 13L, 5L, 56L, 56L, 30L, 27L, 27L, 26L, 24L, 22L,
22L, 20L, 19L, 18L, 17L, 15L, 15L, 13L, 12L, 12L, 11L, 11L, 10L,
9L, 8L, 8L, 8L, 8L, 7L, 7L, 6L, 5L, 4L, 2L, 2L, 2L, 34L, 30L,
28L, 25L, 22L)), row.names = c(1L, 3L, 4L, 33L, 41L, 65L, 74L,
81L, 82L, 84L, 86L, 88L, 89L, 97L, 100L, 101L, 102L, 104L, 107L,
108L, 112L, 114L, 116L, 117L, 119L, 120L, 126L, 128L, 129L, 135L,
136L, 137L, 143L, 144L, 145L, 147L, 148L, 150L, 154L, 157L, 160L,
162L, 167L, 168L, 169L, 170L, 171L, 172L, 173L, 174L), class = "data.frame")
AND
w2 <- structure(list(ny_stadie = structure(c(4, 3, 4, 4, 4, 4, 4, 4,
3, 1, 3, 4, 3, 1, 1, 1, 4, 4, 3, 4, 4, 2, 2, 2, 2, 4, 3, 2, 1,
1, 4, 3, 2, 1, 1, 1, 4, 3, 4, 2, 4, 4, 4, 4, 3, 4, 2, 2, 4, 4
), class = "AsIs"), n.fjernet = c(10L, 13L, 9L, 7L, 7L, 7L, 6L,
6L, 5L, 4L, 3L, 37L, 26L, 19L, 17L, 15L, 9L, 57L, 55L, 33L, 33L,
33L, 28L, 27L, 27L, 26L, 23L, 23L, 23L, 22L, 21L, 21L, 20L, 20L,
19L, 18L, 18L, 18L, 17L, 17L, 16L, 16L, 16L, 15L, 15L, 15L, 14L,
14L, 13L, 13L)), row.names = c(2L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 34L, 35L, 36L, 37L, 38L,
39L, 40L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L,
53L, 54L, 55L), class = "data.frame")

You can use grobs (graphical objects) from grid package.
See this following code:
library(grid)
library(gridExtra)
vp = viewport(x=.8725, y=.4, width=.15, height=.3, just="left", clip="off", angle=0)
pushViewport(vp)
tbl <- textGrob("Text here", gp = gpar(fontsize=12, col="blue"))
grid.draw(tbl)
upViewport()

Related

Reordering a bar chart to be an ascending manner

I have a bar chart presenting the number of samples, with the number of responders and non-responders in multiple datasets. I want to order it according to the number of samples in each dataset, in an ascending manner (starting with lowest samples number and going to the top).
the code:
myData <- data.frame(Articles, Samples_number, Response, No_Response)
library(ggplot2)
myData |>
tidyr::pivot_longer(c(Response, No_Response)) |>
ggplot(aes(Articles, value, fill = name)) +
geom_col(position = position_stack()) +
theme(axis.text.x = element_text(angle = 60, vjust = 1, hjust=1))
the plot:
The dataframe that contains all the information, myData :
structure(list(Articles = c("Allen.SKCM", "Auslander.SKCM", "Braun.KIRC",
"Cho.NSCLC", "Freeman.SKCM (MGH)", "He.THCA", "Hoffman.BLCA (IMvigor210)",
"Hugo.SKCM", "Liu.SKCM", "Lozano.SKCM", "McDermott.KIRC (IMmotion150)",
"Motzer.KIRC", "Newell.SKCM", "Pender.PAN", "Riaz.SKCM", "Rizos.SKCM",
"Snyder.BLCA"), Samples_number = c(49L, 181L, 44L, 14L, 354L,
165L, 298L, 47L, 39L, 25L, 21L, 53L, 9L, 82L, 165L, 119L, 16L
), Response = c(10L, 57L, 22L, 2L, 197L, 48L, 68L, 27L, 7L, 13L,
7L, 34L, 4L, 17L, 14L, 47L, 4L), No_Response = c(39L, 124L, 22L,
12L, 157L, 117L, 230L, 20L, 32L, 12L, 14L, 19L, 5L, 65L, 24L,
72L, 12L)), class = "data.frame", row.names = c(NA, -17L))
You can use the following code:
myData <- structure(list(Articles = c("Allen.SKCM", "Auslander.SKCM", "Braun.KIRC",
"Cho.NSCLC", "Freeman.SKCM (MGH)", "He.THCA", "Hoffman.BLCA (IMvigor210)",
"Hugo.SKCM", "Liu.SKCM", "Lozano.SKCM", "McDermott.KIRC (IMmotion150)",
"Motzer.KIRC", "Newell.SKCM", "Pender.PAN", "Riaz.SKCM", "Rizos.SKCM",
"Snyder.BLCA"), Samples_number = c(49L, 181L, 44L, 14L, 354L,
165L, 298L, 47L, 39L, 25L, 21L, 53L, 9L, 82L, 165L, 119L, 16L
), Response = c(10L, 57L, 22L, 2L, 197L, 48L, 68L, 27L, 7L, 13L,
7L, 34L, 4L, 17L, 14L, 47L, 4L), No_Response = c(39L, 124L, 22L,
12L, 157L, 117L, 230L, 20L, 32L, 12L, 14L, 19L, 5L, 65L, 24L,
72L, 12L)), class = "data.frame", row.names = c(NA, -17L))
library(ggplot2)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(tidyr)
myData %>%
pivot_longer(c(Response, No_Response)) %>%
group_by(Articles) %>%
mutate(total = sum(value)) %>%
ggplot(aes(x = Articles, y = value, fill = name)) +
geom_col(aes(x = reorder(Articles, total, sum), y = value), position = position_stack()) +
theme(axis.text.x = element_text(angle = 60, vjust = 1, hjust=1))
Created on 2022-08-28 with reprex v2.0.2
use reorder function:
library(ggplot2)
myData |>
tidyr::pivot_longer(c(Response, No_Response)) |>
ggplot(aes(reorder(Articles, value), value, fill = name)) +
geom_col(position = position_stack()) +
theme(axis.text.x = element_text(angle = 60, vjust = 1, hjust=1))

R: group of charts

I would like to create a collection of plots like this:
So far I have managed to create a single such plot:
ggplot (df, aes (x, y)) + geom_point (col = 'yellow') + xlab ("A") + ylab ("B") + ggtitle ("Dose0.1") + geom_abline (slope = 1, linetype = 2, color = "red")
With calibrated measures on the axes
Preferably in the form of a function
Example data:
structure(list(Np. = 1:32, A = c(62L, 62L, 54L, 54L, 10L, 10L,
14L, 14L, 50L, 50L, 43L, 43L, 22L, 22L, 48L, 48L, 34L, 34L, 57L,
57L, 60L, 60L, 1L, 1L, 63L, 63L, 2L, 2L, 44L, 44L, 34L, 57L),
B = c(1L, 7L, 2L, 29L, 1L, 15L, 27L, 28L, 14L, 15L, 48L,
49L, 1L, 2L, 1L, 21L, 18L, 19L, 23L, 24L, 14L, 15L, 29L,
31L, 1L, 2L, 1L, 36L, 2L, 19L, 19L, 23L), Dose = c(0.1, 1,
10, 1, 1, 0.1, 1, 1, 1, 1, 1, 1, 1, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1, 0.1, 0.1, 10, 10, 10, 10, 10, 10, 10, 1, 1
)), class = "data.frame", row.names = c(NA, -32L))
If you want to write it in your own function, you can combine the {{}} from rlang to tell R that it should look for your x and y arguments inside the data like this:
df <- structure(list(Np. = 1:32, A = c(62L, 62L, 54L, 54L, 10L, 10L,
14L, 14L, 50L, 50L, 43L, 43L, 22L, 22L, 48L, 48L, 34L, 34L, 57L,
57L, 60L, 60L, 1L, 1L, 63L, 63L, 2L, 2L, 44L, 44L, 34L, 57L),
B = c(1L, 7L, 2L, 29L, 1L, 15L, 27L, 28L, 14L, 15L, 48L,
49L, 1L, 2L, 1L, 21L, 18L, 19L, 23L, 24L, 14L, 15L, 29L,
31L, 1L, 2L, 1L, 36L, 2L, 19L, 19L, 23L), Dose = c(0.1, 1,
10, 1, 1, 0.1, 1, 1, 1, 1, 1, 1, 1, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1, 0.1, 0.1, 10, 10, 10, 10, 10, 10, 10, 1, 1
)), class = "data.frame", row.names = c(NA, -32L))
library(ggplot2)
plot <- function(dataframe, xvalue, yvalue, grid){
ggplot(dataframe, aes({{xvalue}}, {{yvalue}})) +
geom_point(col = 'yellow') +
xlab ("A") + ylab ("B") +
geom_abline(slope = 1, linetype = 2, color = "red") +
theme_bw() +
facet_grid(~Dose)
}
plot(df, A, B, "Dose")
Created on 2022-07-04 by the reprex package (v2.0.1)
You may want to change formatting a little but essentially:
df$dose <- factor(df$Dose)
ggplot (df, aes (A, B)) +
geom_point(aes(color = dose, shape = dose)) +
xlab ("A") +
ylab ("B") +
geom_abline(slope = 1, linetype = 2, color = "black") +
facet_wrap(vars(dose)) +
theme_bw()

Place a background image in a specific position in ggplot2 and take measurements

My question is quite challenging for me so far. Hope with your help we can get what I need.
I want to place an image as background of a ggplot.
Data to reproduce : Two objects are necessary: a data frame and an image.
DATA at the end of this question.
Background image:
And this is the image to place as background (molar.png):
What I got so far...
I ggplotted:
library(png)
library(grid)
library(ggplot2)
img <- readPNG("images/molar.png")
g <- rasterGrob(img, interpolate = TRUE)
ggplot(df), aes(x = X, y = Y)) +
coord_fixed(ratio = .75) +
annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) +
geom_point(alpha = .20, size = 1, shape = 19, color = "red") +
stat_smooth(method = 'lm', formula = y ~ poly(x, 3)) +
xlim(0, 100) + ylim(0, 100) +
theme_minimal() +
geom_hline(aes(yintercept = 0), color = "red", lty = 2) +
geom_vline(aes(xintercept = 0), color = "red", lty = 2)
I got this result:
... and what I really want
1. Adapt the regression to this line
Take this red horizontal line as reference:
The X axis (from 0 to 100) must be fitted to this line, as shown now:
This is really what I want: to adapt the background image (without modifying its proportion) to that horizontal line, from the cusp tip (gray) to the ending of the white area to the right.
This would require to select two landmarks in the image, but don't know how to make it automatic by simply selecting one or two points, so that the regression automatically fits that distance.
2. Take measurements
I would like to measure the distance between the highest point of the regression and the point [100, 0], as shown below in green line.
The point here, how can we reference if we are having a scale in the image?
DATA
df <- structure(list(tooth_num = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10),
sample = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L,
24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L,
36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L,
48L, 49L, 50L, 51L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L,
23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L,
35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L,
33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L,
45L, 46L, 47L, 48L, 49L, 50L, 51L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L,
31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L,
43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L,
17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L,
29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L,
41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L,
27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L,
39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L,
51L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L,
26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L,
38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L,
50L, 51L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L,
37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L,
49L, 50L, 51L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L,
24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L,
36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L,
48L, 49L, 50L, 51L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L,
23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L,
35L, 36L, 37L, 38L, 39L, 40L, 41L), X = c(0, 1.96207644325269,
3.96448989844662, 6.02285180886395, 8.15165005779206, 10.3635651674945,
12.6674140636077, 15.0640931778694, 17.5406465345979, 20.0647832611694,
22.5857329433686, 25.0458992379799, 27.3978582481916, 29.6291517474813,
31.8764771189544, 34.0520372099874, 36.1615029782313, 38.2134690535817,
40.2184171634735, 42.1879211839819, 44.1341445581471, 46.0695527612659,
48.0067272490216, 49.9582712234201, 51.9366936524031, 53.9541918066236,
56.0223057345439, 58.1471219902002, 60.015986446532, 62.0418690161973,
64.172643764213, 66.3646706538791, 68.5820610043302, 70.7926665021678,
72.9630123083219, 75.0533364802678, 77.0143642675254, 78.7889946597798,
80.3221949636097, 81.6792186440018, 83.1246290439824, 84.6572566946537,
86.2607918541562, 87.9199855179157, 89.6207074088368, 91.349834829432,
93.0950207010492, 94.844403612905, 96.5863082060859, 98.3089189787115,
100, 0, 2.07242714587787, 4.28691224245265, 6.60638277527078,
8.99634804343432, 11.4282251674021, 13.8802080085279, 16.3366019674999,
18.7865642588865, 21.2228067680933, 23.6405691464549, 26.0268342309397,
28.2980527055826, 30.4950596311624, 32.6499592979795, 34.7798224410736,
36.8956207286784, 39.0058437957066, 41.1183659656274, 43.2421092543673,
45.3894713560051, 47.5991212687389, 49.7770452245596, 51.9171025815641,
54.0147450240845, 56.0668835223753, 58.0722874535502, 60.0316719092865,
61.9474399302204, 63.8232002348162, 65.6632101130593, 67.4719472029522,
69.2537602596947, 71.1020020072457, 73.0197406878018, 74.8895017058263,
76.7134344938606, 78.4953847484249, 80.2407780197449, 81.9562954259909,
83.649499477401, 85.3283767502077, 87.0008805605653, 88.6745443161437,
90.3562154355033, 92.0029343703826, 93.595173297479, 95.1912911811735,
96.7911009335273, 98.3943073713479, 100, 0, 2.49538787860394,
4.98986333706054, 7.48094091039875, 9.95158514589746, 12.3765352721187,
14.7826711324534, 17.1741487059107, 19.5379450224354, 21.8376445004796,
24.2011429944043, 26.5151298348149, 28.7199538624058, 31.0167238490571,
33.2844073975993, 35.4322146421557, 37.6300939882099, 39.8422715265431,
41.8385466322099, 43.9606111742119, 46.1772777113709, 48.0735169131695,
50.1458450809683, 52.0775711992983, 54.0389983532847, 56.0114855556445,
57.9507899054059, 59.8445463497116, 61.7655941740918, 63.7919980969677,
65.7952774486913, 67.8300149894114, 69.6945929413499, 71.6911766995294,
73.5625774964864, 75.3913842466844, 77.1888383995349, 78.9539192357634,
80.672317733178, 82.2770969086854, 83.9169027294331, 85.5602445166866,
87.1949684008868, 88.8468983089335, 90.5308901736114, 92.1034422363185,
93.6509365884513, 95.3521507218448, 96.9695007185512, 98.5200274462478,
100, 0, 1.93071662500976, 3.82909585694513, 5.83503737371176,
7.96719181032991, 10.2303413170764, 12.617316402646, 15.1102082752161,
17.6402520534245, 20.1564846032436, 22.6509074609361, 25.0393836587477,
27.3129712478007, 29.4988321446333, 31.6158908190034, 33.5547876344398,
35.4063709991687, 37.2999307397267, 39.3177890463815, 41.2304325787261,
43.1170170017018, 45.1909193214654, 47.1049295380901, 49.1859515610248,
51.13271739105, 53.1310164292379, 55.0797239964915, 57.1128373874235,
58.9454191107869, 60.9254683084337, 62.9947826516433, 65.0902258076096,
67.1539265387035, 69.1321933211508, 71.0068236131378, 72.9528127482717,
74.868864278393, 76.7358744964615, 78.5828026706554, 80.4923369340278,
82.44389985077, 84.3433495275878, 86.0966137745744, 87.9057900961145,
89.7809605893561, 91.5773662545089, 93.2971230872706, 94.8659471916182,
96.5480144068937, 98.2832055612151, 100, 0, 2.45904597118919,
4.9478077699383, 7.4437174468872, 9.93045045419645, 12.3969081092835,
14.8359017068762, 17.2430125015322, 19.6157029336795, 21.9526351315638,
24.2532312350846, 26.5173310764965, 28.744978623416, 30.9362680921638,
33.0912151854599, 35.2096628761033, 37.2911746284744, 39.334940182215,
41.3396279466586, 43.3031840060133, 45.2225306271349, 47.2687426646706,
49.3178157378126, 51.3497697054769, 53.3645511784153, 55.3621224700994,
57.3424678778091, 59.3055999637205, 61.2515438521856, 63.1803529324531,
65.0920931559475, 66.9868618795333, 68.8647627411635, 70.7259245031432,
72.5704916304973, 74.3986274315152, 76.2105077766622, 78.0063242391239,
79.7862840948059, 81.5506040412458, 83.2995196192455, 85.0332663696068,
86.7521175196599, 88.4563337345588, 90.1461348523852, 91.8219291438623,
93.4838736361913, 95.1323766000954, 96.7676892790966, 98.3900943221571,
100, 0, 2.20427029931411, 4.42577825043187, 6.67629529636218,
8.96662563154085, 11.3064974908959, 13.704119943729, 16.165246307201,
18.6916215311874, 21.2788860284595, 23.9143289820342, 26.5756256258544,
29.2320665145903, 31.8490369716412, 34.3727083595587, 36.7961343283599,
39.1127253229244, 41.3113092041144, 43.3888560030568, 45.3501991751572,
47.2064997097139, 48.9732280089765, 50.6683743389121, 52.3111665976677,
53.9212675271295, 55.5183816810814, 57.1220463657154, 58.7515758904346,
60.4258971077205, 62.1633013292058, 63.9808505967227, 65.8934996324456,
67.912799670054, 70.0333597621695, 71.9831740002692, 73.9087652121441,
75.8101919344515, 77.6875628781259, 79.5410090537812, 81.3706865591696,
83.1767905164818, 84.9595299852075, 86.7191558367347, 88.4559245173709,
90.170123135482, 91.862066674033, 93.5320896282075, 95.1805376430287,
96.8077452136806, 98.414102584544, 100, 0, 2.50973310686108,
4.98257000649406, 7.40768627831619, 9.78047063985944, 12.100599944502,
14.3704650807463, 16.5940944776443, 18.776452301705, 20.9230915203372,
23.0399794423239, 25.1335076302947, 27.2106366228331, 29.2791814137006,
31.3594526601995, 33.4580064720123, 35.556233172214, 37.6533199380137,
39.7484638590935, 41.8408600426407, 43.9297035958428, 46.0141896258872,
48.0934993624991, 50.1668041229306, 52.2332633294661, 54.2920126144546,
56.3421658028046, 58.3828149119835, 60.4130261870291, 62.4318202756028,
64.4382019654095, 66.4311244992937, 68.4095034527027, 70.3722187161805,
72.3180946704221, 74.2459160462301, 76.1544160295474, 78.0422683314784,
79.9081070132353, 81.7505086436864, 83.5679982468404, 85.3590473193511,
87.1220777955072, 88.8554739421999, 90.5575664989655, 92.2266544854268,
93.8610012363035, 95.458856208853, 97.0184430879027, 98.537991505764,
100, 0, 2.49186292873155, 4.96628290858449, 7.40387310725186,
9.79133340002794, 12.1468199057625, 14.5011896071325, 16.8431655039685,
19.1723761535772, 21.4884872575346, 23.7911793751244, 26.0801603047613,
28.355162607706, 30.6159386554963, 32.8622655825162, 35.0939428097114,
37.310792044589, 39.5126572812178, 41.6993973713744, 43.8708934533968,
46.0270489521849, 48.1677771977769, 50.2930162830572, 52.4027142060487,
54.4968362987667, 56.5753602746497, 58.6382811811283, 60.6856064470565,
62.7173459775728, 64.7335369169464, 66.7342089805929, 68.7194141704892,
70.6892069648972, 72.6436517472169, 74.582822805987, 76.5067919534617,
78.4156508121718, 80.30948109951, 82.1883843431457, 83.8953343826177,
85.318702783443, 86.7569115580089, 88.2078484355329, 89.6694432420707,
91.1396480902398, 92.6164522369269, 94.0978597967267, 95.5818971707953,
97.0665932365733, 98.5499867766401, 100, 0, 2.61369623570294,
5.25019204546923, 7.89758672867171, 10.4854413123113, 13.0066240676632,
15.4846710718853, 17.9159547041448, 20.2976684759407, 22.6276875072264,
24.9044541625748, 27.1268476764071, 29.2940720764344, 31.4055784162507,
33.4609732842652, 35.4599616217844, 37.4022781047122, 39.2876574089524,
41.115772453938, 42.8862115298645, 44.5984417012627, 46.5824735364946,
48.8579364441288, 51.0689873528466, 53.2187049370753, 55.31212578009,
57.3558486751465, 59.3576503629965, 61.3261515894915, 63.2705517814855,
65.2004117555501, 67.125505044989, 69.0556829505137, 71.0007693255153,
72.9704141903561, 74.9739450593852, 77.0201427878221, 79.1169465130639,
80.9682934274075, 82.7378404654242, 84.4621062867744, 86.1441466931183,
87.7873262684694, 89.3952520481705, 90.9717460715737, 92.5207813382925,
94.0464474990516, 95.5529302701972, 97.0444725499921, 98.5253927168307,
100, 0, 2.19489342240264, 4.47470248895734, 6.80636996136228,
9.16189235515265, 11.5204119968896, 13.8679818386464, 16.1962336516669,
18.5008000956494, 20.7800403414259, 23.0340446346007, 25.2640080457511,
27.4717901812673, 29.6596690589774, 31.8301824946609, 33.9860569994518,
36.1301804326855, 38.2656102060449, 40.395611569574, 42.5237505919975,
44.6539625286031, 46.790726843019, 48.9392449637073, 51.1057000819157,
53.0838372365286, 55.0005198693747, 56.9159691456296, 58.8292579968134,
60.7394374767241, 62.645542230868, 64.5465987006055, 66.4416169190052,
68.3295795719832, 70.2094638760246, 72.080216965747, 73.9407777716216,
75.7900606116825, 77.6269798039636, 79.4504168499154, 81.2592587204191,
83.0523732433488), Y = c(84.5741422911491, 87.0989688246201,
89.5436034157802, 91.8694746551154, 94.0314174040144, 95.9740138468311,
97.628391911438, 98.9112343041615, 99.7302288176452, 100,
99.6682935009841, 98.7381965579207, 97.2664228638507, 95.3825982722905,
93.5434433368078, 91.50049262398, 89.2915552625009, 86.9514674858642,
84.511940176201, 82.0015588642778, 79.4462792120302, 76.8706085478357,
74.2982919192514, 71.7531887159568, 69.2602636348217, 66.8466919870944,
64.5423551809367, 62.3722941413001, 59.6800326256192, 57.2857466826492,
55.128758759083, 53.1294867372666, 51.2007256913408, 49.2527551687403,
47.1957784888164, 44.9429337520794, 42.418488359019, 39.5725891439776,
36.3973083864229, 33.0253591771941, 29.7461795438129, 26.5669349259918,
23.4758099710143, 20.4586262556193, 17.4994139966193, 14.5814411300049,
11.6872895390296, 8.79946487886403, 5.90043469063777, 2.97289519972717,
0, 93.0321380957158, 95.1946109521693, 96.937054277536, 98.2619255824812,
99.1910694062447, 99.7577986711693, 100, 99.9550821661862,
99.6575185832176, 99.1377550776607, 98.4215955114931, 97.4779796804826,
95.9441517048638, 94.1389735933651, 92.2010899059795, 90.1898222195824,
88.1388247774415, 86.0724678936469, 84.0123913148843, 81.9837162612796,
80.0234419211725, 78.2597001700458, 76.3926747068224, 74.4111019409554,
72.3108177571526, 70.0927095898208, 67.7621020453996, 65.3282107888812,
62.802504203367, 60.1968602570691, 57.5234982391254, 54.7931356266002,
52.0153976695973, 49.3678395136313, 46.8461605150396, 44.2290481856401,
41.5261960397215, 38.748799403644, 35.9094871516561, 33.021434271488,
30.098088807609, 27.1525574835635, 24.19719611686, 21.2436096189696,
18.3024472027724, 15.3103597044707, 12.2378569960892, 9.17074715833242,
6.10882539864554, 3.05175039610287, 0, 100, 99.9740960784806,
99.8730270144876, 99.6594688780895, 99.1648671200451, 98.300448086114,
97.3281159413371, 96.2806584450564, 95.1069839916948, 93.6992988433163,
92.5227992310794, 91.1519207300211, 89.4389990501897, 88.0315526476314,
86.5030621141021, 84.637382900149, 82.9008651750625, 81.2041782110219,
79.064856495856, 77.1370635776142, 75.4555767641426, 73.1766285349799,
71.1390523302985, 68.8176471360649, 66.5503178701644, 64.3037992816136,
61.9957638533255, 59.6077485751849, 57.270625947771, 55.1882053198138,
53.005988938906, 50.8933669646611, 48.4803231663425, 46.2904669191802,
43.8645308465569, 41.369278904061, 38.8252432322521, 36.2327421588907,
33.5735116287118, 30.7665372266409, 28.0047653665761, 25.244744309195,
22.4736613621324, 19.7247419854022, 17.0183591556834, 14.1736629139801,
11.3015506938947, 8.6188037004008, 5.82611425658707, 2.95264914351926,
0, 86.7221127164863, 89.2450865945842, 91.8256626160176,
94.2050712850442, 96.3082958568556, 98.0567601186487, 99.356578317864,
100, 99.8266960099512, 99.3672567218446, 98.6837623193952,
97.4546359200075, 95.8095875992727, 93.8391732848531, 91.6986699837336,
89.1914649315853, 86.5315472203614, 83.9427805951582, 81.5889388575256,
79.0374892354799, 76.4382738493923, 74.2129556980193, 71.6847000287053,
69.5197780116735, 67.026504640704, 64.6334322074442, 62.1466653908716,
59.8252416036741, 57.210640130131, 54.8147737058654, 52.5672567218449,
50.3760405702802, 48.1148980958759, 45.6822122284949, 43.0613338436512,
40.5655726724713, 38.0157305521002, 35.3812266768728, 32.7135011003732,
30.1526743852262, 27.6670940579847, 25.0888527413645, 22.2776767773419,
19.7712372021815, 17.1514304851209, 14.4034446464453, 11.542359582815,
8.48492967180167, 5.57098842216043, 2.73145153573813, 0,
99.1041781658029, 99.7254865136605, 100, 99.9614316109632,
99.6447768919466, 99.0834281892782, 98.3070217828948, 97.341621109093,
96.2090754809024, 94.9278903961505, 93.5136855943403, 91.9791492509625,
90.3350457026248, 88.5899864186136, 86.7511628918963, 84.8242550277467,
82.8134769494328, 80.7219434437174, 78.5514867381084, 76.302473278107,
73.9737121158334, 71.8911107192181, 69.810524772861, 67.694531029918,
65.5438623813919, 63.3593433296612, 61.1416609600414, 58.8917313862862,
56.6101958880234, 54.2979247733192, 51.9556967388641, 49.5842904813491,
47.1845305031526, 44.757241306653, 42.303109977166, 39.8229610170695,
37.317527317367, 34.7876333804369, 32.2340120972821, 29.657396358906,
27.058564861999, 24.438158886189, 21.7969571281666, 19.1356924789353,
16.4549604124345, 13.7555396253553, 11.0379797859501, 8.30305959090951,
5.55132870848586, 2.78342841830685, 0, 84.1515543172144,
86.2722836260793, 88.3566153916604, 90.3773896250419, 92.3062620354674,
94.111690717205, 95.7577913244362, 97.203231722867, 98.4009161759049,
99.2995644137824, 99.8474619227218, 100, 99.7284790643066,
99.0275302806241, 97.8277140842702, 96.2611985608363, 94.3983312397508,
92.2676143186827, 89.9054453409169, 87.3514589414394, 84.6443817904904,
81.8193876527848, 78.9076236667722, 75.9361708679116, 72.9289916301439,
69.9079560608225, 66.8938683956418, 63.9077697306659, 60.9718854638001,
58.1105727362662, 55.3511099671633, 52.7239337138365, 50.2623228580521,
47.9794231502588, 45.4070011187705, 42.7981815439979, 40.1541092510553,
37.4757316814164, 34.7641541834675, 32.0204031521378, 29.2455049823579,
26.4404465923295, 23.6062938537105, 20.7439547312464, 17.8544950965959,
14.9388623912317, 11.9979251031726, 9.0326701506196, 6.04400549831871,
3.03283911101569, 0, 100, 99.5848739044175, 98.8739209129315,
97.9105346461211, 96.7351022995956, 95.3831954679074, 93.885250878182,
92.2670226841415, 90.5504870541479, 88.7545871260625, 86.8960843842295,
84.9905164585802, 83.0528356573708, 81.0986594271243, 79.1673905588146,
77.2717198905873, 75.3754106896234, 73.4768134130185, 71.5743849399925,
69.6665023331719, 67.7516224717761, 65.8282022350241, 63.8947517131965,
61.9497011799818, 59.9915873311911, 58.0188670460438, 56.0301302314122,
54.0238603720464, 51.9985941637575, 49.9528949078877, 47.8852726947172,
45.794397247711, 43.6787786571497, 41.5370334354364, 39.3678047005055,
37.1697621758216, 34.941522373788, 32.6818614399924, 30.3895023089609,
28.063247731812, 25.7019536707251, 23.304582510003, 20.8700966339479,
18.3975648489857, 15.8861889891947, 13.3352240997155, 10.7440582533417,
8.11223915605116, 5.43939433041456, 2.72533753771655, 0,
100, 99.9134879636606, 99.4737726511386, 98.7119319033914,
97.6645725261045, 96.4711111592938, 95.2721931018034, 94.0226109361477,
92.7232680879358, 91.374959571704, 89.9785165390125, 88.5348785524954,
87.0449851747857, 85.5095952833957, 83.9297207150073, 82.3061926211812,
80.6400228385995, 78.9320063817987, 77.1831189504364, 75.3942278330975,
73.5662725924159, 71.7000843799518, 69.7965666213147, 67.8565504680649,
65.8809393458113, 63.8706005431396, 61.8262568005362, 59.7488476806353,
57.6390236498756, 55.4977604079147, 53.3256361471427, 51.123554293169,
48.8921653124316, 46.6322280824431, 44.344429206666, 42.0294914255877,
39.6880290686225, 37.3207287392334, 34.9282409038592, 32.3093546108134,
29.3214008878868, 26.3486608522194, 23.3891108304469, 20.4407632862286,
17.5015222721514, 14.5693279778263, 11.6421205928639, 8.71769575877807,
5.79402980220384, 2.86895450167932, 0, 99.0881176828924,
99.616812993443, 99.9245775334157, 100, 99.4144184933504,
98.4080380989905, 97.2482296158507, 95.9447863261935, 94.5072176490275,
92.9445788221548, 91.2653289705444, 89.4773594926569, 87.5879656741198,
85.6037331424258, 83.5306797985592, 81.3743977486237, 79.139712667937,
76.8311379822374, 74.4527045497319, 72.0079322747694, 69.5001707437473,
67.4173241176181, 65.7355478830473, 63.9261751158092, 62.0062376111431,
59.9926536189868, 57.9018588217461, 55.7494373120646, 53.5502067518011,
51.3181332130511, 49.0667285867045, 46.8089938097941, 44.5579865920031,
42.3268498019911, 40.129152103299, 37.979256976578, 35.89220917429,
33.8840753566102, 31.5408977402496, 29.095103557573, 26.6000023276786,
24.0608455207656, 21.4827994480562, 18.8707181711938, 16.2292854338693,
13.56295788917, 10.8759367132551, 8.1722811506567, 5.45590851427953,
2.73059418540176, 0, 96.4662652426023, 98.0232502530471,
99.1147667554613, 99.7607331141328, 100, 99.8803419056255,
99.4511603186742, 98.7585534337238, 97.843294734107, 96.7405371746194,
95.4801583016932, 94.0874997966255, 92.5842056245715, 90.989010880653,
89.3184813331895, 87.587358543869, 85.8094473196242, 83.9978129241588,
82.1654220154131, 80.3260794003192, 78.4945266405658, 76.6880690477,
74.9274631350027, 73.2399733961649, 70.9563625122581, 68.4738638027609,
65.9881111030584, 63.4970829949925, 60.9982157287041, 58.4893399773897,
55.9680398998363, 53.4319489577125, 50.8788978242146, 48.3064706581295,
45.7125474355354, 43.0948602238647, 40.4513876049598, 37.7800095548987,
35.0788032612873, 32.3458952146129, 29.5794612082463)), .Names = c("tooth_num",
"sample", "X", "Y"), row.names = c(NA, 500L), class = "data.frame")

Why can I compute a mixed model with lme, but not with lmer?

I'm attempting to run a mixed model in R with the lme4 package.
library(lme4)
m1 <- lmer(rt2 ~ condition + rt1 + condition*rt1 + (1 | subj) , data = df)
I get the following error message: "Error: number of levels of each grouping factor must be < number of observations". The error message makes sense because I have 46 observations and 46 participants.
However, I can run the same model with the nlme package without any error message:
library(nlme)
m2 <- lme(rt2 ~ condition + rt1 + condition*rt1, data = df, random = ~ 1 | subj)
Why can I run the model with nlme but not with lme4? Is it ok to interpret the results from the second model?
My data looks something like this:
df <- structure(list(subj = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 21L, 22L, 23L, 24L, 101L, 102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L, 114L, 115L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L), condition = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), rt1 = c(46.8105499999999, 76.370818692028, 59.778292128193, 24.883242857143, 21.226639867672, -21.03400237712, 51.0391505102041, 69.012199029126, 179.014368072932, 46.15812435546, 78.448862797267, 66.473437810945, 108.827163519139, 73.6389999424071, 89.829873737374, 86.251484994273, 88.412976831683, 203.226219871798, 11.293038244384, 115.500764155017, 101.520579909222, 85.912837438554, 163.099186091535, 178.796075376344, 172.592490740741, 151.171400701587,311.318290305009, 124.107150003926, 103.790202412333, 196.283178266371, 82.789046400187, 98.4326761904771, 149.504007586534, 178.81566904762, 101.143787442057, 338.369788946405, 88.04309478022, 156.055273468631, 102.908947097659, 103.923616878268, 237.106966609653, 215.461850843354, 18.017751248898, 224.736390582656, 218.40048947368, 76.260591417598), rt2 = c(35.5943547858769, 121.999683164729, 70.1167870281901, 46.1811456947171, 81.779957179474, 148.111105656111, 149.603506610939, 55.862105226296, 143.207197715373, 34.887128220687, 38.299248863636, 95.2843711396361, 97.0520967833841, 107.832187165775, 91.821258606965, 99.957164922988, 84.3041822023661, 237.325642673231, 26.771263754184, 109.846556878307, 169.615306823133, 86.5665153566119, 305.010019372861, 220.792146257438, 223.790192245031, 158.432720855615, 313.328780519479, 190.188307417046, 116.799351221776, 181.491207732176, 99.9429508950891, 245.527463325564, 307.644367565137, 267.87756818182, 183.903568478261, 295.491853846154, 87.341270500928, 220.234276984125, 185.366267480097, 244.873834818776, 329.992332220494, 298.392818041876, 91.081530603128, 150.335149529625, 328.832859339508, 365.738806305878)), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L), class = "data.frame")
subj condition rt1 rt2
1 0 46.81055 35.59435
2 0 76.37082 121.99968
3 0 59.77829 70.11679
4 0 24.88324 46.18115
5 0 21.22664 81.77996
6 0 -21.03400 148.11111
The variable "condition" is between-subjects.

Set ggmap boundary based on Latitude and Longitude

So I have R program, and am struggling with getting all points in map
library(ggmap)
library(ggplot2)
setwd("d:/GIS/")
sep <- read.csv("SEP_assets_csv.csv")
Sub1 <- sep[grep("SEP.12", names(sep))]
sep$newCol <- 100*rowSums(Sub1)/rowSums(sep[4:7])
# create a new grouping variable
Percent_SEP12_Assets <- ifelse(sep[,8] >= 50, "Over 50", "Under 50")
# get the map
map <- get_map("Kissena Park, Queens", zoom = 13, maptype = 'roadmap')
# plot the map and use the grouping variable for the fill inside the aes
ggmap(map) +
geom_point(data=sep, aes(x = Longitude, y = Latitude, color=Percent_SEP12_Assets ), size=9, alpha=0.6) +
scale_color_manual(breaks=c("Over 50", "Under 50"), values=c("green","red"))
And here is output map
I wish to zoom in enough without cutting out data points, but no matter location I pick on map, the data keeps getting cut, i.e. Removed 2 rows containing missing values (geom_point).
Is there a way to set boundaries based on the extremities of latitude and longitude? The csv I import at
sep <- read.csv("SEP_assets_csv.csv")
Has list of latitude and longitude.
Help!
Coordinates
Latitude Longitude
40.758365 -73.824407
40.774168 -73.818543
40.761748 -73.811379
40.765602 -73.828293
40.751762 -73.81778
40.764834 -73.789712
40.777951 -73.842932
40.76501 -73.794319
40.785959 -73.817349
40.755764 -73.799256
40.745593 -73.829283
40.789929 -73.839501
40.760072 -73.783908
40.726437 -73.807592
40.741093 -73.808757
40.720926 -73.823358
40.729642 -73.81781
40.724191 -73.80937
40.782346 -73.77844
40.778164 -73.799841
40.775122 -73.8185
40.760344 -73.817909
40.792326 -73.809516
40.78322 -73.806977
40.73106 -73.805449
40.736521 -73.813001
40.783714 -73.795027
40.770194 -73.82762
40.735855 -73.823583
40.74943 -73.82141
40.769753 -73.832001
40.754465 -73.826204
40.738775 -73.823892
40.764868 -73.826819
40.738332 -73.82028
40.735017 -73.821339
40.72535 -73.811325
40.721466 -73.820401
dput
> dput(sep)
structure(list(School = structure(1:38, .Label = c("Queens\\25Q020",
"Queens\\25Q021", "Queens\\25Q022", "Queens\\25Q023", "Queens\\25Q024",
"Queens\\25Q025", "Queens\\25Q029", "Queens\\25Q032", "Queens\\25Q079",
"Queens\\25Q107", "Queens\\25Q120", "Queens\\25Q129", "Queens\\25Q130",
"Queens\\25Q154", "Queens\\25Q163", "Queens\\25Q164", "Queens\\25Q165",
"Queens\\25Q168", "Queens\\25Q169", "Queens\\25Q184", "Queens\\25Q185",
"Queens\\25Q189", "Queens\\25Q193", "Queens\\25Q194", "Queens\\25Q200",
"Queens\\25Q201", "Queens\\25Q209", "Queens\\25Q214", "Queens\\25Q219",
"Queens\\25Q237", "Queens\\25Q242", "Queens\\25Q244", "Queens\\25Q425",
"Queens\\25Q460", "Queens\\25Q499", "Queens\\25Q515", "Queens\\25Q707",
"Queens\\25Q792"), class = "factor"), Latitude = c(40.758365,
40.774168, 40.761748, 40.765602, 40.751762, 40.764834, 40.777951,
40.76501, 40.785959, 40.755764, 40.745593, 40.789929, 40.760072,
40.726437, 40.741093, 40.720926, 40.729642, 40.724191, 40.782346,
40.778164, 40.775122, 40.760344, 40.792326, 40.78322, 40.73106,
40.736521, 40.783714, 40.770194, 40.735855, 40.74943, 40.769753,
40.754465, 40.738775, 40.764868, 40.738332, 40.735017, 40.72535,
40.721466), Longitude = c(-73.824407, -73.818543, -73.811379,
-73.828293, -73.81778, -73.789712, -73.842932, -73.794319, -73.817349,
-73.799256, -73.829283, -73.839501, -73.783908, -73.807592, -73.808757,
-73.823358, -73.81781, -73.80937, -73.77844, -73.799841, -73.8185,
-73.817909, -73.809516, -73.806977, -73.805449, -73.813001, -73.795027,
-73.82762, -73.823583, -73.82141, -73.832001, -73.826204, -73.823892,
-73.826819, -73.82028, -73.821339, -73.811325, -73.820401), Windows.SEP.11 = c(48L,
154L, 11L, 62L, 20L, 72L, 9L, 37L, 8L, 22L, 9L, 47L, 44L, 99L,
78L, 91L, 42L, 122L, 55L, 14L, 162L, 108L, 89L, 87L, 23L, 14L,
75L, 74L, 141L, 73L, 43L, 14L, 534L, 189L, 128L, 10L, 79L, 38L
), Mac.SEP.11 = c(49L, 0L, 180L, 2L, 202L, 116L, 41L, 1L, 17L,
22L, 33L, 43L, 1L, 28L, 2L, 0L, 238L, 13L, 76L, 55L, 76L, 42L,
0L, 1L, 12L, 0L, 16L, 10L, 1L, 7L, 0L, 1L, 1L, 67L, 16L, 7L,
31L, 24L), Windows.SEP.12 = c(52L, 252L, 1L, 2L, 12L, 45L, 108L,
15L, 14L, 4L, 19L, 21L, 46L, 90L, 10L, 86L, 15L, 76L, 122L, 2L,
9L, 52L, 39L, 120L, 43L, 17L, 9L, 54L, 19L, 199L, 40L, 25L, 64L,
164L, 14L, 27L, 45L, 2L), Mac.SEP.12 = c(73L, 2L, 91L, 53L, 288L,
6L, 2L, 107L, 109L, 97L, 41L, 18L, 12L, 16L, 2L, 2L, 270L, 32L,
45L, 92L, 54L, 190L, 1L, 4L, 19L, 53L, 1L, 10L, 0L, 61L, 50L,
27L, 27L, 25L, 3L, 1L, 43L, 0L), newCol = c(56.3063063063063,
62.2549019607843, 32.5088339222615, 46.218487394958, 57.4712643678161,
21.3389121338912, 68.75, 76.25, 83.1081081081081, 69.6551724137931,
58.8235294117647, 30.2325581395349, 56.3106796116505, 45.4935622317597,
13.0434782608696, 49.1620111731844, 50.4424778761062, 44.4444444444444,
56.0402684563758, 57.6687116564417, 20.9302325581395, 61.734693877551,
31.0077519379845, 58.4905660377358, 63.9175257731959, 83.3333333333333,
9.9009900990099, 43.2432432432432, 11.8012422360248, 76.4705882352941,
67.6691729323308, 77.6119402985075, 14.5367412140575, 42.4719101123596,
10.5590062111801, 62.2222222222222, 44.4444444444444, 3.125)), .Names = c("School",
"Latitude", "Longitude", "Windows.SEP.11", "Mac.SEP.11", "Windows.SEP.12",
"Mac.SEP.12", "newCol"), row.names = c(NA, -38L), class = "data.frame")
You haven't provided us with any of the data, so I'm going to give an example using a dataset in the historydata package. Instead of getting a map based on a location and a zoom, you can get a map based on the bounding box of the latitudes and longitudes in your dataset.
library(historydata)
library(ggmap)
data("catholic_dioceses")
bbox <- make_bbox(catholic_dioceses$long, catholic_dioceses$lat, f = 0.01)
map <- get_map(bbox)
ggmap(map) +
geom_point(data=catholic_dioceses, aes(x = long, y = lat))
Note that the f = argument to make_bbox() lets you control how much padding there is around your map.
In your case, I think this will work:
library(ggmap)
bbox <- make_bbox(sep$Longitude, sep$Latitude, f = 0.01)
map <- get_map(bbox)
ggmap(map) +
geom_point(data=sep, aes(x = Longitude, y = Latitude,
color = Percent_SEP12_Assets),
size = 9, alpha = 0.6) +
scale_color_manual(breaks=c("Over 50", "Under 50"), values=c("green","red"))

Resources