Barplots using centroids in R

时间:2018-06-04 16:56:57

标签: r ggplot2 bar-chart polygon errorbar

I'll like to create several barplots using centroid locations to position them. I already have a plot code for the polygons I want to combine them with. These are from a floor plan and not a geographical area around the world. Unfortunately, I have several points unlike the example in the link below which has just three points. How do I plot this using ggplot2 to cover all my points? Here is the sample ggplot code I want to add the barplot to:

ggplot() + theme_minimal()+ theme(plot.title = element_text(hjust = 0.5,face="bold",size=14),line=element_line(size=0.2),
                              panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
                              axis.text.x=element_blank(),axis.text.y=element_blank(),strip.text = element_text(size=11, face = "bold"),axis.title.x = element_blank(),
                              axis.title.y = element_blank(),legend.title=element_text(size=9, face = "bold"))+
  geom_polygon(aes(x =long, y = lat, group = group), size=0.5,color="black",fill="black",alpha=0.2, data =shp1_data.frame)+
  geom_polygon(aes(x =long, y = lat, group = group), size=0.5,color="white",fill="black",alpha=0.2, data =shp4_data.frame)

Example of barplots of geographical locations

Codes for the image attached

head(read.table("Sampledata.txt",header=T),15)
   Location_i variable      value        x         y
1        A005     Head  0.0000000 1238.509 -970.4791
2        A005     Hair  0.0000000 1238.509 -970.4791
3        A005    Knees  0.1666667 1238.509 -970.4791
4        A005     Ears  0.0000000 1238.509 -970.4791
5        A005    Heart  0.0000000 1238.509 -970.4791
6        A005    Mouth -0.1666667 1238.509 -970.4791
7        A005     Toes  0.0000000 1238.509 -970.4791
8        A028     Head  0.0000000 1538.509 -870.4791
9        A028     Hair  0.0000000 1538.509 -870.4791
10       A028    Knees  0.0000000 1538.509 -870.4791
11       A028     Ears  0.0000000 1538.509 -870.4791
12       A028    Heart  1.0000000 1538.509 -870.4791
13       A028    Mouth -1.0000000 1538.509 -870.4791
14       A028     Toes  0.0000000 1538.509 -870.4791
15       A030     Toes  0.0000000 1738.509 -870.6731

I have put a sample of the data Here in my drive with the x and y location fields, value, variable ad location ID. the plot is grouped around each centroid (location_i) using the variable field.

##To read in the text file after downloading
  A1<-read.table("Sampledata.txt",header=T)

0 个答案:

没有答案