I want to graphically compare carbon pools under different forms of land use. I am reading in my data, later I remove a factor level.
However, when I display the data the legend does not work. The first legend symbol has no label, and the deleted factor (SPEZIALKULTUREN) is still shown.
how can I control the legend?
A sample of the data is shown below enter image description here
agdata <- read.csv("C:/Jandl/LfdProjekte/2017FAO/2020Paper/Agdata.csv", header = FALSE, sep = ";", dec = ",")
colnames(agdata) <- c("State","AgType","Cpool")
agdata$Cpool <- as.numeric(agdata$Cpool)
levels(agdata$AgType)[levels(agdata$AgType)=="ACKERLAND"] <- "crop"
levels(agdata$AgType)[levels(agdata$AgType)=="ALMEN"] <- "alpine meadow"
levels(agdata$AgType)[levels(agdata$AgType)=="EXTENSIVES GRÜNLAND *"] <- "extens grassland"
levels(agdata$AgType)[levels(agdata$AgType)=="INTENSIVES GRÜNLAND**"] <- "intens grassland"
levels(agdata$AgType)[levels(agdata$AgType)=="WEINGARTEN***"] <- "vineyard"
#dropping SPEZIALKULTUREN
agdata <- subset(agdata,agdata$AgType !="SPEZIALKULTUREN")
agdata <- subset(agdata,agdata$State !="")
agdata <- subset(agdata,agdata$State !="Wien")
library(lattice)
colors = c("lightsalmon3", "lightgoldenrod2", "cadetblue4", "yellow", "red", "blue")
barchart(
data = agdata,
origin = 0,
Cpool ~ State,
groups = AgType ,
xlab = list (
label = "State",
font = 2,
cex = 1),
ylab= list (
label = "C pool t/ha",
font = 2,
cex = 1),
#ylim=c(0,25),
labels = TRUE,
auto.key = list(space="top", columns= 3),
par.settings = list(superpose.polygon = list(col = colors)))