How to Plot a US state in R? - r

I can plot data for a particular state in the whole US map. But I want to plot only the state map with the data (Oklahoma).
How can I do it in R?
ggplot() +
geom_polygon( data=all_states, aes(x=long, y=lat,group=group),colour="black", fill="white" )+
geom_point(data=stations,aes(x=long,y=lat),,colour="red",)+
ggtitle("Distribution of Flash Flood Events in CONUS")+
xlab('Longitude')+
ylab('Latitude')
dput(stations)
structure(list(coop = c(340017L, 340179L, 340256L, 340292L, 340548L,
340593L, 340908L, 341243L, 341504L, 341724L, 341828L, 342678L,
342912L, 342944L, 343497L, 343628L, 343821L, 343871L, 344055L,
344204L, 344235L, 344298L, 344573L, 344766L, 344861L, 345063L,
345509L, 345779L, 345855L, 346130L, 346139L, 346278L, 346629L,
346638L, 346670L, 346926L, 346935L, 347012L, 347254L, 348501L,
348677L, 349395L, 349422L, 349445L), lat = c(34.7864, 34.5903,
34.2208, 34.1714, 36.7683, 36.8125, 36.7236, 36.8003, 35.1756,
36.7747, 36.3225, 34.0003, 36.4194, 35.2164, 35.6267, 36.5914,
35.8161, 35.585, 36.0942, 34.9894, 35.0567, 36.8589, 36.7222,
36.9031, 35.8583, 34.6097, 34.8911, 35.505, 36.8833, 35.7781,
36.2283, 36.8914, 36.1217, 35.4253, 35.6239, 34.7253, 36.6692,
36.2886, 35.0539, 36.1175, 35.9369, 34.1747, 35.52, 35.4814),
long = c(-96.685, -99.3344, -95.615, -97.1294, -96.0261,
-100.5308, -102.4806, -99.6403, -98.5794, -98.3583, -95.5808,
-96.3686, -97.8747, -99.8628, -98.3225, -101.6181, -97.395,
-99.3953, -97.835, -99.0525, -96.3861, -101.2172, -97.7903,
-102.965, -97.9294, -98.4572, -99.5017, -96.9767, -94.8833,
-95.3339, -99.17, -97.0586, -98.315, -96.3033, -96.025, -97.2814,
-96.3472, -97.2897, -94.6264, -97.095, -94.9644, -97.9964,
-98.6986, -95.2039), elev = c(309.4, 420.6, 143.3, 268.2,
217.9, 751.3, 1259.7, 588.3, 451.4, 359.7, 179.2, 182.9,
379.5, 627.9, 487.7, 1008.9, 338.3, 554.7, 357.8, 474.3,
260.6, 912.9, 318.5, 1325.9, 320, 350.5, 486.2, 281.9, 245.4,
157.9, 576.1, 347.5, 370.3, 285, 197.2, 286.5, 254.5, 312.4,
134.1, 272.8, 259.1, 278, 493.2, 167.6), state = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "OK", class = "factor"),
name = structure(1:44, .Label = c("ADA", "ALTUS IRIG RSCH STN",
"ANTLERS", "ARDMORE", "BARTLESVILLE MUNI AP", "BEAVER", "BOISE CITY 2 E",
"BUFFALO 2 SSW", "CARNEGIE 5 NE", "CHEROKEE", "CLAREMORE 2 ENE",
"DURANT", "ENID", "ERICK", "GEARY", "GOODWELL RSCH STN",
"GUTHRIE 5S", "HAMMON 3 SSW", "HENNESSEY 4 ESE", "HOBART MUNI AP",
"HOLDENVILLE 2SSE", "HOOKER", "JEFFERSON", "KENTON", "KINGFISHER",
"LAWTON", "MANGUM", "MEEKER 5 W", "MIAMI", "MUSKOGEE", "MUTUAL",
"NEWKIRK 1NW", "OKEENE", "OKEMAH", "OKMULGEE WTR WKS", "PAULS VALLEY 4 WSW",
"PAWHUSKA", "PERRY", "POTEAU WTR WKS", "STILLWATER 2 W",
"TAHLEQUAH", "WAURIKA", "WEATHERFORD", "WEBBERS FALLS 5 WSW"
), class = "factor")), .Names = c("coop", "lat", "long",
"elev", "state", "name"), class = "data.frame", row.names = c(NA,
-44L))

You can use the maps package. There are a lot of simple options for the appearance of the map. Here are two very basic ones. As far as this problem goes, the maps package doesn't differ from ggplot2 very much at all, other than the fact that it's easier to code in maps.
> library(maps)
> par(mfrow = c(1, 2))
> map('state', region = 'Oklahoma')
> map('county', region = 'Oklahoma')
ADD:
Since you added the data, here is an exaggerated plot which assumes the data is called dat.
> map('county', region = 'Oklahoma')
> with(dat, points(lat ~ long, pch = 19, col = 'red'))

Edit. update according to comment
Since Geekuna is using ggplot, I am giving an answer for ggplot
m = map_data('state', region = 'Oklahoma')
ggplot() +
geom_polygon( data=m, aes(x=long, y=lat,group=group),colour="black", fill="white" )+
geom_point(data=stations,aes(x=long,y=lat),,colour="red",)+
geom_text(data=stations, aes(x=long, y=lat,label=name), size=2, hjust=-0.1) +
ggtitle("Distribution of Flash Flood Events in CONUS")+
xlab('Longitude')+
ylab('Latitude')+
coord_fixed()

You could probably use ggcounty package if you want to show county for state as well.
library(devtools)
install_github(repo="hrbrmstr/ggcounty")
library(ggcounty)
ok <- ggcounty("Oklahoma")
ok$gg
Edited after dput from OP
ok$gg +
geom_point(data=stations,aes(x=long,y=lat),,colour="red",size=5)+
ggtitle("Distribution of Flash Flood Events in CONUS")+
xlab('Longitude')+
ylab('Latitude')
The output is as follows:
You may want to remove xlab and ylab. I hope it helped you.

Related

stat_compare_means with multiple groups

I need some help with stat_compare_means and multiple groups.
Here is what my data look like.
> head(df_annot)
Row.names Diversity_sh Diversity_si Evenness Chao1 Location Bean Fungi Insect
1 R-B1 1.314181 0.6040213 0.3053349 91.00000 Root Bean M- NI
2 R-B2 1.323718 0.6117602 0.3075507 77.43750 Root Bean M- NI
3 R-B3 1.249950 0.5737293 0.2877545 81.50000 Root Bean M- NI
4 R-BF-1 1.177111 0.5414276 0.2693958 92.33333 Root Bean M+ NI
5 R-BF-2 1.191254 0.5252688 0.2742420 79.54545 Root Bean M+ NI
6 R-BF-3 1.397233 0.6285945 0.3179540 85.50000 Root Bean M+ NI
Here is a graph and I would like ALL comparisons labelled.
Here is some code. I know that I don't have my_comparisons correct, but I don't know where to start for the two groups. I want to compare M+/Insect to M-/Insect and M+/Insect to M+/NI etc.., all two-way comparisons. Any suggestions would be great. thanks
my_comparisons<- list( c("M+", "M-"), c("Insect", "NI"))
ggplot(df_annot,aes_string(x="Insect",y=index,fill="Fungi"))+
geom_boxplot(alpha=0.8)+
geom_point(aes(fill=Fungi),size = 3, shape = 21,position = position_jitterdodge(jitter.width = 0.02,jitter.height = 0))+
stat_compare_means(comparison=my_comparisons,label="p.format",method="wilcox.test")+
#ggtitle(df_name)+
ylab(paste(index))+
xlab("")+
# scale_x_discrete(labels= c("M+","M-","soil alone"))+
theme(plot.title = element_text(size = 18, face = "bold"))+
theme(axis.text=element_text(size=14),
axis.title=element_text(size=14)) +
theme(legend.text=element_text(size=14),
legend.title=element_text(size=14)) +
theme(strip.text.x = element_text(size = 14))
dput(df_annot)
structure(list(Row.names = structure(c("R-B1", "R-B2", "R-B3",
"R-BF-1", "R-BF-2", "R-BF-3", "R-BFi-1", "R-BFi-2", "R-Bi-1",
"R-Bi-2", "R-Bi-3"), class = "AsIs"), Diversity_sh = c(1.31418133185869,
1.32371839350534, 1.24994951615418, 1.17711111336449, 1.19125374868316,
1.39723272927515, 1.34145146126423, 1.21674449259962, 1.20721660188555,
1.17245529262564, 1.20912937911657), Diversity_si = c(0.604021268328531,
0.611760247980402, 0.573729285531772, 0.541427625516077, 0.525268755766239,
0.628594506768001, 0.597250229879166, 0.554646956896473, 0.548992316400345,
0.531291238688503, 0.583806537719818), Evenness = c(0.305334910927276,
0.307550737463383, 0.287754490536268, 0.269395848882803, 0.274241968272787,
0.317954009728278, 0.305260435164649, 0.276882141486585, 0.273949061455415,
0.269914321375221, 0.275929262855007), Chao1 = c(91, 77.4375,
81.5, 92.3333333333333, 79.5454545454545, 85.5, 87.5, 90.5454545454545,
89.3333333333333, 88.6666666666667, 88.0769230769231), Location = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Root", "Rhizospheric Soil"
), class = "factor"), Bean = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L), .Label = "Bean", class = "factor"),
Fungi = structure(c(2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L), .Label = c("M+", "M-"), class = "factor"), Insect = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L), .Label = c("Insect",
"NI"), class = "factor")), row.names = c(NA, -11L), class = "data.frame")
facet_wrap() might help you as discussed here
ggplot(df_annot, aes(x=df_annot$Insect, y= df_annot$Evenness)) +
facet_wrap(~df_annot$Fungi)+
geom_boxplot(alpha=0.8) +
geom_point()+
stat_compare_means(comparisons = list(c("Insect", "NI") ), label="p.format",method="wilcox.test")
EDIT
ok here is a - not too elegant - solution without faceting.
Create a new variable containing Insect info and Fungi status:
df_annot$var <- paste(df_annot$Insect,df_annot$Fungi, sep = "_" )
Then build the contrasts
my_comparisons <- rev(list(c("Insect_M-","Insect_M+"),c("NI_M-","Insect_M-"),c("NI_M+","Insect_M-"),
c("Insect_M+", "NI_M-"), c("Insect_M+", "NI_M+"), c("NI_M-","NI_M+")))
and plot your graph
ggplot(df_annot,aes_string(x="var",y="Evenness",fill="Fungi"))+
geom_boxplot(alpha=0.8)+
geom_point(aes(fill=Fungi),size = 3, shape = 21,position = position_jitterdodge(jitter.width = 0.02,jitter.height = 0))+
stat_compare_means(comparison=my_comparisons,label="p.format",method="wilcox.test")+
#ggtitle(df_name)+
ylab(paste("Evenness"))+
xlab("")+
# scale_x_discrete(labels= c("M+","M-","soil alone"))+
theme(plot.title = element_text(size = 18, face = "bold"))+
theme(axis.text=element_text(size=14),
axis.title=element_text(size=14)) +
theme(legend.text=element_text(size=14),
legend.title=element_text(size=14)) +
theme(strip.text.x = element_text(size = 14))
you might want to make better names and such. but this could be what you are looking for.

How to annotate geom_segment arrows in ggplot

I have a dataframe:
df_sites <- structure(list(x = c(1.04092250164696, -0.383065216420003, 0.396244810279309,
0.970078841220606, 1.70624019153651, 3.16514402752826, 0.683787687531189,
0.00206174639359557, 0.885459199930364, 0.990634067372794, 0.228548628266029,
5.12827669944002, 0.0950586619539368, -0.275846514997531, 1.5525132408558,
-1.29950430377717, -0.990922674400145, 0.185830660119637, 0.00602127943634668,
-1.02247155743703, -0.251974618425098, 1.87788540164332, 1.28325669941297,
1.02150538568984, -0.865622294371786, -1.96452990510675, -0.524866180755096,
2.17941326700128, -1.34324588367972, -1.81439562296687, -1.13470999575871,
-0.493658775981049, -0.296149601541577, 0.447503914837335, -0.269452469430389,
0.0127337699647291, -1.04287439571777, -0.613105026144241, -1.3890917214799,
-1.90860630718699, -1.16104734632228, -0.584089855574213, -1.2278237710839,
-0.937664406699838, 1.09181991754655, -0.565406792755387, -0.58204838078486,
0.842304932110318), y = c(-3.45147995394394, 2.29349807839102,
0.174644402446899, 3.8468101986443, 2.6412842200453, -0.0665028396276639,
2.05491741522117, 0.165875878990559, -0.25539122973085, 1.74130285620058,
0.396659954165391, -1.65827015730937, 1.17736501075071, -3.72087159136532,
1.89896109873428, 1.68766224921712, -2.92368548480463, -2.42481488216442,
2.20648524060166, -0.486513106980203, 2.05729614246768, 2.51807338395106,
1.9974880289267, -2.67208900165781, -0.749156762561599, 1.93100782500476,
-4.15965374769117, 3.64156647300722, -2.7010471123406, 0.198076035987165,
1.62736086278764, -1.03740092888219, -3.89989372202828, -0.213429351502094,
-0.408170753360095, -1.61011027424538, -0.213306102694109, -0.154504840231308,
0.118730504697768, 1.91054431185776, 0.255125262080179, 0.612701198243207,
-1.21511378377373, 3.29282161162431, 2.50675599190964, -3.80136136529774,
-1.28545510252701, 3.02158440057367), Sites = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "M", class = "factor")), row.names = c("M.T1.R1.S1.16S.S50",
"M.T1.R1.S2.16S.S62", "M.T1.R1.S3.16S.S74", "M.T1.R2.S1.16S.S86",
"M.T1.R2.S2.16S.S3", "M.T1.R2.S3.16S.S15", "M.T1.R3.S1.16S.S27",
"M.T1.R3.S2.16S.S39", "M.T1.R3.S3.16S.S51", "M.T1.R4.S1.16S.S63",
"M.T1.R4.S2.16S.S75", "M.T1.R4.S3.16S.S87", "M.T2.R1.S1.16S.S53",
"M.T2.R1.S2.16S.S65", "M.T2.R1.S3.16S.S77", "M.T2.R2.S1.16S.S89",
"M.T2.R2.S2.16S.S6", "M.T2.R2.S3.16S.S18", "M.T2.R3.S1.16S.S30",
"M.T2.R3.S2.16S.S42", "M.T2.R3.S3.16S.S54", "M.T2.R4.S1.16S.S66",
"M.T2.R4.S2.16S.S78", "M.T2.R4.S3.16S.S90", "M.T3.R1.S1.16S.S56",
"M.T3.R1.S2.16S.S68", "M.T3.R1.S3.16S.S80", "M.T3.R2.S1.16S.S92",
"M.T3.R2.S2.16S.S9", "M.T3.R2.S3.16S.S21", "M.T3.R3.S1.16S.S33",
"M.T3.R3.S2.16S.S45", "M.T3.R3.S3.16S.S57", "M.T3.R4.S1.16S.S69",
"M.T3.R4.S2.16S.S81", "M.T3.R4.S3.16S.S93", "M.T4.R1.S1.16S.S59",
"M.T4.R1.S2.16S.S71", "M.T4.R1.S3.16S.S83", "M.T4.R2.S1.16S.S95",
"M.T4.R2.S2.16S.S12", "M.T4.R2.S3.16S.S24", "M.T4.R3.S1.16S.S36",
"M.T4.R3.S2.16S.S48", "M.T4.R3.S3.16S.S60", "M.T4.R4.S1.16S.S72",
"M.T4.R4.S2.16S.S193", "M.T4.R4.S3.16S.S203"), class = "data.frame")
which I plot as
p<-ggplot()
p<-p+geom_point(data=df_sites,aes(x,y,colour=Sites), shape = "diamond", size = 5)
df_arrows <- structure(list(x = c(-0.0506556191949347, -0.248732307259684,
0.75), y = c(-0.669658874134264, -0.45802558549515, -0.110871926510315
)), class = "data.frame", row.names = c("`POX-C`", "Protein",
"yield"))
p+geom_segment(data=df_arrows, aes(x = 0, y = 0, xend = x, yend = y),
arrow = arrow(length = unit(0.2, "cm")))
I would like to add annotation to these arrows. How do I do it?
We can use geom_text and the data contained in df_arrows:
library(dplyr) # get %>% and mutate
p <- p+geom_segment(data=df_arrows, aes(x = 0, y = 0, xend = x, yend = y),
arrow = arrow(length = unit(0.2, "cm")))
p + geom_text(data = df_arrows %>% mutate(labs = row.names(.)),
aes(x = x, y = y, label = labs))
If you want the plot to be a little easier on the eyes and avoid plotting over things, you can try the geom_text_repel function from the ggrepel package.

R: ggplot2 histogram fill dodge - prevent partial overlap

I'm trying to plot a histogram with ggplot2 comparing 2 periods of time. I want the bars to dodge (i.e. plot side-by-side) and not stack. I've tried this:
qplot(region, data = data, fill = month) +
labs(y = "Sales", fill = "") +
geom_bar(position = "dodge")
The dodge partially works but I'm still getting overlap:
How can I get the bars to position side-by-side properly?
Update
Output of dput(head(data, 20)) as requested by #RuiBarradas in the comments:
structure(list(month = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("May 2018",
"May 2019 (so far)"), class = "factor"), region = structure(c(5L,
6L, 6L, 5L, 5L, 4L, 6L, 6L, 4L, 5L, 6L, 5L, 6L, 6L, 5L, 4L, 5L,
5L, 6L, 6L), .Label = c("Abbotsford", "Agassiz", "Bowen Island",
"Burnaby East", "Burnaby North", "Burnaby South", "Chilliwack",
"Cloverdale", "Coquitlam", "Cultus Lake", "Harrison Hot Springs",
"Hope", "Islands-Van. & Gulf", "Ladner", "Langley", "Maple Ridge",
"Mission", "N. Delta", "New Westminster", "North Surrey", "North Vancouver",
"Pemberton", "Pitt Meadows", "Port Coquitlam", "Port Moody",
"Richmond", "Rosedale", "Sardis", "South Surrey White Rock",
"Squamish", "Sunshine Coast", "Surrey", "Tsawwassen", "Vancouver East",
"Vancouver West", "West Vancouver", "Whistler", "Yarrow", "Harrison Mills / Mt Woodside"
), class = "factor")), row.names = c(NA, 20L), class = "data.frame")
Apparently it is a qplot error, that can be reproduced with the data in the OP's link and the question's code.
library(ggplot2)
qplot(region, data = data, fill = month) +
labs(y = "Sales") +
geom_bar(position = position_dodge())
But with ggplot everything works as expected.
ggplot(data, aes(x = region, fill = month)) +
geom_bar(position = position_dodge()) +
theme(axis.text.x = element_text(angle=90, hjust=1)) +
labs(y = "Sales")

Combine bar plot and stat_smooth() line from different data sets in ggplot2

I'm trying to overlay a stat_smooth() line from one dataset over a bar plot of another. Both csv files draw from the same dataset, but I had to make a new one for the bar plot because I had to add a few columns (including error bars) that wouldn't make sense in the big csv. So, I have code for the bar plot, and code for the line made using stat_smooth, but can't figure out how to combine them. I just want a graph with the line on top of the bars. Here's the code for the bar plot:
`e <- read.csv("Retro Complex.csv", header=T, sep=",")
e <- subset(e, Accuracy != 0)
limits <- aes(ymax = Confidence + SE, ymin = Confidence - SE)
e$Complexity <- factor(e$Complexity)
p <- ggplot(e, aes(e$Complexity, Confidence))
p +
geom_bar(position = "dodge", stat = "identity") +
geom_errorbar(limits, position = "dodge", width = 0.25) +
coord_cartesian(ylim=c(0,1)) +
scale_y_continuous(labels = percent) +
ggtitle("Retro")`
And here's for the line
`ggplot(retroacc, aes(x=Complexity.Sample, y=risk)) +
stat_smooth(aes(x=Complexity.Sample, y=risk), data=retroacc,
method="glm", method.args=list(family="binomial"), se=FALSE) +
ylim(0,1)`
Here's what they both look like:
Stat_smooth() line:
Barplot:
Sample Data
For the bar plot:
structure(list(Complexity = structure(1:5, .Label = c("1", "2",
"3", "4", "5"), class = "factor"), Accuracy = c(1L, 1L, 1L, 1L,
1L), Risk = c(0.69297164, 0.695793434, 0.695891571, 0.746606335,
0.748717949), SE = c(0.003621776, 0.004254081, 0.00669456, 0.008114764,
0.021963804), Proportion = c(0.823475656, 0.809299751, 0.863727821,
0.94724695, 0.882352941), SEAcc = c(0.002716612, 0.003267882,
0.004639995, 0.004059001, 0.015325003)), .Names = c("Complexity",
"Accuracy", "Confidence", "SE", "Proportion", "SEAcc"), row.names = c(1L,
3L, 5L, 7L, 9L), class = "data.frame")
For the line:
structure(list(risk = c(0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 0L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), acc = c(0L, 1L, 1L, 1L,
0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L),
Uniqueness = c(0.405166959, 0.407414244, 0.285123931, 0.248994487,
0.259019778, 0.334552913, 0.300580793, 0.354632526, 0.309841996,
0.331460876, 0.289981111, 0.362405881, 0.37389863, 0.253672193,
0.342903451, 0.294459829, 0.387447291, 0.519657612, 0.278964406
), Average.Similarity = c(0.406700667, 0.409547355, 0.275663862,
0.240909144, 0.251796956, 0.31827466, 0.240574971, 0.349093002,
0.34253811, 0.348084627, 0.290495997, 0.318312198, 0.404143605,
0.290789337, 0.293259599, 0.320214236, 0.382449298, 0.506295194,
0.335167223), Complexity.Sample = c(8521L, 11407L, 3963L,
2536L, 2327L, 3724L, 4005L, 5845L, 5770L, 5246L, 3629L, 3994L,
4285L, 1503L, 8222L, 3683L, 5639L, 10288L, 3076L)), .Names = c("risk",
"acc", "Uniqueness", "Average.Similarity", "Complexity.Sample"
), class = "data.frame", row.names = c(NA, -19L))
So yeah, if any of you guys know how to combine these into one plot please let me know!!

How can I make the label not overlap the point in R?

I am using this code to plot the following figure:
m = map_data('state', region = 'Oklahoma')
ggplot() +
geom_polygon(data=m, aes(x=long, y=lat,group=group),colour="black", fill="white" )+
geom_point(data=stations,aes(x=long,y=lat),,colour="red",)+
geom_text(data=stations,aes(x=,long,y=lat,label=name,fill = NULL, size=1))+
xlab('Longitude')+
ylab('Latitude')+
coord_fixed()
How can I stop the text from overlapping over the ticker? Thanks!
Data
dput(stations)
structure(list(coop = c(340017L, 340179L, 340256L, 340292L, 340548L,
340593L, 340908L, 341243L, 341504L, 341724L, 341828L, 342678L,
342912L, 342944L, 343497L, 343628L, 343821L, 343871L, 344055L,
344204L, 344235L, 344298L, 344573L, 344766L, 344861L, 345063L,
345509L, 345779L, 345855L, 346130L, 346139L, 346278L, 346629L,
346638L, 346670L, 346926L, 346935L, 347012L, 347254L, 348501L,
348677L, 349395L, 349422L, 349445L), lat = c(34.7864, 34.5903,
34.2208, 34.1714, 36.7683, 36.8125, 36.7236, 36.8003, 35.1756,
36.7747, 36.3225, 34.0003, 36.4194, 35.2164, 35.6267, 36.5914,
35.8161, 35.585, 36.0942, 34.9894, 35.0567, 36.8589, 36.7222,
36.9031, 35.8583, 34.6097, 34.8911, 35.505, 36.8833, 35.7781,
36.2283, 36.8914, 36.1217, 35.4253, 35.6239, 34.7253, 36.6692,
36.2886, 35.0539, 36.1175, 35.9369, 34.1747, 35.52, 35.4814),
long = c(-96.685, -99.3344, -95.615, -97.1294, -96.0261,
-100.5308, -102.4806, -99.6403, -98.5794, -98.3583, -95.5808,
-96.3686, -97.8747, -99.8628, -98.3225, -101.6181, -97.395,
-99.3953, -97.835, -99.0525, -96.3861, -101.2172, -97.7903,
-102.965, -97.9294, -98.4572, -99.5017, -96.9767, -94.8833,
-95.3339, -99.17, -97.0586, -98.315, -96.3033, -96.025, -97.2814,
-96.3472, -97.2897, -94.6264, -97.095, -94.9644, -97.9964,
-98.6986, -95.2039), elev = c(309.4, 420.6, 143.3, 268.2,
217.9, 751.3, 1259.7, 588.3, 451.4, 359.7, 179.2, 182.9,
379.5, 627.9, 487.7, 1008.9, 338.3, 554.7, 357.8, 474.3,
260.6, 912.9, 318.5, 1325.9, 320, 350.5, 486.2, 281.9, 245.4,
157.9, 576.1, 347.5, 370.3, 285, 197.2, 286.5, 254.5, 312.4,
134.1, 272.8, 259.1, 278, 493.2, 167.6), state = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "OK", class = "factor"),
name = structure(1:44, .Label = c("ADA", "ALTUS IRIG RSCH STN",
"ANTLERS", "ARDMORE", "BARTLESVILLE MUNI AP", "BEAVER", "BOISE CITY 2 E",
"BUFFALO 2 SSW", "CARNEGIE 5 NE", "CHEROKEE", "CLAREMORE 2 ENE",
"DURANT", "ENID", "ERICK", "GEARY", "GOODWELL RSCH STN",
"GUTHRIE 5S", "HAMMON 3 SSW", "HENNESSEY 4 ESE", "HOBART MUNI AP",
"HOLDENVILLE 2SSE", "HOOKER", "JEFFERSON", "KENTON", "KINGFISHER",
"LAWTON", "MANGUM", "MEEKER 5 W", "MIAMI", "MUSKOGEE", "MUTUAL",
"NEWKIRK 1NW", "OKEENE", "OKEMAH", "OKMULGEE WTR WKS", "PAULS VALLEY 4 WSW",
"PAWHUSKA", "PERRY", "POTEAU WTR WKS", "STILLWATER 2 W",
"TAHLEQUAH", "WAURIKA", "WEATHERFORD", "WEBBERS FALLS 5 WSW"
), class = "factor")), .Names = c("coop", "lat", "long",
"elev", "state", "name"), class = "data.frame", row.names = c(NA,
-44L))
The labels can still overlap each other, but they can be offset from the dots.
The command below adds some transparency, an offset to the text position, and makes it left justified.
geom_text(data=stations,aes(x=long+.05,y=lat,label=name,fill = NULL, size=1,hjust=0,alpha=.5))
To manually adjust the position of some labels in ggplot, you can add an "overlap" field containing a small offset to administer to each latitude:
overlapDOWN = c("JEFFERSON","HENNESSEY 4 ESE","GUTHRIE 5S","WEATHERFORD")
overlapUP = c("GEARY","STILLWATER 2 W","ADA","LAWTON")
stations$overlap=0
stations$overlap[stations$name %in% overlapUP] = .05
stations$overlap[stations$name %in% overlapDOWN] = -.05
Then use:
geom_text(data=stations,aes(x=long+.05,y=lat+overlap,label=name,fill = NULL, hjust=0,alpha=.5),size=3)

Resources