The problem was the fill = as.character(type). Once I replaced it with just fill = type, it worked properly.