3

I am working with qmap (R package ggmap) and when I enter the following code:

qmap("Rotterdam", maptype = "terrain", zoom = 13) +
geom_polygon(aes(x = long, y = lat, group = group, fill = pOpleidingHigh), 
             data = dfDataPlus,
             colour = "white", 
             alpha = 0.8, size = 0.5)

I get the following output:

Picture 1

As you can see the picture is very chaotic and unclear, because of the multiple squares.

Below an example of my data:

    > dput(dfDataPlus[1:5,1:29])

structure(list(id = c("2651", "2651", "2651", "2651", "2651"), long = c(4.49239869, 4.49238217, 4.47727316, 4.48418196, 4.49243175), lat = c(51.99922025, 51.99921236, 51.98782511, 51.99653866, 51.99923602), order = c(235L, 236L, 398L, 282L, 234L), hole = c(FALSE, FALSE, FALSE, FALSE, FALSE), piece = structure(c(1L, 1L, 1L, 1L, 1L), .Label = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"), class = "factor"), group = structure(c(1L, 1L, 1L, 1L, 1L), .Label = c("2651.1", "2651.2", "2651.3", "2651.4", "2651.5", "2651.6", "2651.7", "2651.8", "2652.1", "2652.2", "2652.3", "2652.4", "2652.5", "2652.6", "2652.7", "2652.8", "2652.9", "2661.1", "2661.2", "2662.1", "2662.2", "2665.1", "2671.1", "2671.2", "2671.3", "2671.4", "2671.5", "2671.6", "2671.7", "2671.8", "2671.9", "2671.10", "2672.1", "2672.2", "2672.3", "2672.4", "2672.5", "2672.6", "2673.1", "2673.2", "2673.3", "2673.4", "2675.1", "2676.1", "2678.1", "2681.1", "2681.2", "2684.1", "2685.1", "2685.2", "2691.1", "2691.2", "2691.3", "2691.4", "2691.5", "2691.6", "2691.7", "2691.8", "2691.9", "2692.1", "2693.1", "2693.2", "2693.3", "2694.1", "2694.2", "2694.3", "2694.4", "2711.1", "2711.2", "2711.3", "2711.4", "2711.5", "2711.6", "2712.1", "2712.2", "2712.3", "2712.4", "2712.5", "2712.6", "2712.7", "2712.8", "2712.9", "2712.10", "2712.11", "2713.1", "2713.2", "2713.3", "2713.4", "2713.5", "2715.1", "2715.2", "2716.1", "2717.1", "2718.1", "2718.2", "2718.3", "2718.4", "2718.5", "2719.1", "2719.2", "2719.3", "2719.4", "2721.1", "2722.1", "2722.2", "2722.3", "2722.4", "2722.5", "2723.1", "2723.2", "2724.1", "2724.2", "2725.1", "2725.2", "2726.1", "2727.1", "2727.2", "2728.1", "2729.1", "2729.2", "2731.1", "2735.1", "2741.1", "2741.2", "2741.3", "2742.1", "2742.2", "2742.3", "2743.1", "2743.2", "2751.1", "2752.1", "2761.1", "2761.2", "2771.1", "2801.1", "2802.1", "2803.1", "2803.2", "2804.1", "2805.1", "2806.1", "2806.2", "2806.3", "2807.1", "2808.1", "2809.1", "2811.1", "2821.1", "2825.1", "2831.1", "2840.1", "2841.1", "2841.2", "2851.1", "2855.1", "2861.1", "2865.1", "2871.1", "2871.2", "2872.1", "2872.2", "2901.1", "2902.1", "2902.2", "2903.1", "2904.1", "2905.1", "2906.1", "2907.1", "2908.1", "2909.1", "2911.1", "2912.1", "2913.1", "2913.2", "2913.3", "2914.1", "2914.2", "2921.1", "2921.2", "2922.1", "2922.2", "2923.1", "2924.1", "2924.2", "2924.3", "2925.1", "2925.2", "2926.1", "2931.1", "2935.1", "2941.1", "2951.1", "2951.2", "2952.1", "2952.2", "2953.1", "2954.1", "2954.2", "2957.1", "2957.2", "2959.1", "2961.1", "2964.1", "2964.2", "2965.1", "2967.1", "2967.2", "2968.1", "2969.1", "2971.1", "2973.1", "2974.1", "2974.2", "2974.3", "2975.1", "2975.2", "2975.3", "2977.1", "2981.1", "2981.2", "2981.3", "2982.1", "2983.1", "2984.1", "2985.1", "2985.2", "2986.1", "2986.2", "2987.1", "2987.2", "2988.1", "2989.1", "2991.1", "2991.2", "2992.1", "2992.2", "2992.3", "2993.1", "2993.2", "2994.1", "2995.1", "2995.2", "2995.3", "3011.1", "3012.1", "3013.1", "3013.2", "3014.1", "3015.1", "3015.2", "3016.1", "3021.1", "3021.2", "3022.1", "3023.1", "3024.1", "3025.1", "3026.1", "3027.1", "3028.1", "3029.1", "3031.1", "3032.1", "3033.1", "3034.1", "3035.1", "3035.2", "3036.1", "3037.1", "3037.2", "3038.1", "3038.2", "3038.3", "3039.1", "3041.1", "3042.1", "3042.2", "3043.1", "3043.2", "3043.3", "3044.1", "3044.2", "3045.1", "3045.2", "3045.3", "3046.1", "3047.1", "3047.2", "3051.1", "3052.1", "3053.1", "3054.1", "3055.1", "3056.1", "3059.1", "3059.2", "3061.1", "3062.1", "3063.1", "3064.1", "3065.1", "3066.1", "3067.1", "3068.1", "3068.2", "3068.3", "3069.1", "3069.2", "3071.1", "3072.1", "3072.2", "3073.1", "3074.1", "3074.2", "3074.3", "3075.1", "3075.2", "3076.1", "3077.1", "3078.1", "3078.2", "3078.3", "3079.1", "3081.1", "3082.1", "3082.2", "3083.1", "3084.1", "3084.2", "3084.3", "3084.4", "3084.5", "3085.1", "3085.2", "3085.3", "3086.1", "3087.1", "3088.1", "3088.2", "3089.1", "3089.2", "3089.3", "3111.1", "3111.2", "3112.1", "3112.2", "3113.1", "3114.1", "3115.1", "3116.1", "3117.1", "3117.2", "3118.1", "3118.2", "3119.1", "3119.2", "3121.1", "3122.1", "3123.1", "3124.1", "3125.1", "3125.2", "3131.1", "3132.1", "3132.2", "3133.1", "3133.2", "3133.3", "3134.1", "3135.1", "3136.1", "3136.2", "3137.1", "3137.2", "3138.1", "3141.1", "3142.1", "3143.1", "3144.1", "3145.1", "3146.1", "3147.1", "3151.1", "3155.1", "3161.1", "3161.2", "3161.3", "3161.4", "3162.1", "3165.1", "3171.1", "3172.1", "3172.2", "3176.1", "3181.1", "3191.1", "3192.1", "3193.1", "3194.1", "3195.1", "3196.1", "3196.2", "3197.1", "3198.1", "3198.2", "3199.1", "3201.1", "3202.1", "3203.1", "3204.1", "3205.1", "3206.1", "3206.2", "3207.1", "3208.1", "3209.1", "3211.1", "3211.2", "3212.1", "3214.1", "3216.1", "3218.1", "3221.1", "3221.2", "3221.3", "3221.4", "3221.5", "3221.6", "3222.1", "3222.2", "3222.3", "3222.4", "3222.5", "3222.6", "3222.7", "3223.1", "3223.2", "3223.3", "3223.4", "3223.5", "3223.6", "3223.7", "3223.8", "3223.9", "3224.1", "3224.2", "3224.3", "3225.1", "3225.2", "3225.3", "3225.4", "3227.1", "3231.1", "3231.2", "3232.1", "3232.2", "3233.1", "3233.2", "3234.1", "3235.1", "3237.1", "3237.2", "3237.3", "3237.4", "3238.1", "3238.2", "3241.1", "3243.1", "3244.1", "3245.1", "3247.1", "3248.1", "3249.1", "3251.1", "3252.1", "3253.1", "3255.1", "3256.1", "3256.2", "3257.1", "3257.2", "3258.1", "3258.2", "3258.3", "3258.4", "3258.5", "3261.1", "3261.2", "3262.1", "3262.2", "3263.1", "3264.1", "3264.2", "3265.1", "3265.2", "3267.1", "3271.1", "3273.1", "3274.1", "3281.1", "3284.1", "3286.1", "3291.1", "3292.1", "3293.1", "3295.1", "3297.1", "3299.1", "3311.1", "3312.1", "3312.2", "3313.1", "3314.1", "3315.1", "3315.2", "3316.1", "3317.1", "3317.2", "3317.3", "3317.4", "3318.1", "3318.2", "3319.1", "3319.2", "3319.3", "3319.4", "3328.1", "3328.2", "3329.1", "3329.2", "3329.3", "3331.1", "3332.1", "3332.2", "3332.3", "3332.4", "3333.1", "3333.2", "3333.3", "3334.1", "3334.2", "3335.1", "3336.1", "3336.2", "3336.3", "3336.4", "3336.5", "3341.1", "3342.1", "3342.2", "3342.3", "3342.4", "3343.1", "3343.2", "3343.3", "3343.4", "3343.5", "3343.6", "3343.7", "3344.1", "3344.2", "3344.3"), class = "factor"), X = c(1L, 1L, 1L, 1L, 1L), sumOpleidinghigh = c(99L, 99L, 99L, 99L, 99L), sumOpleidinglow = c(27L, 27L, 27L, 27L, 27L), sumBeperking = c(46L, 46L, 46L, 46L, 46L), sumOuderPersoon = c(152L, 152L, 152L, 152L, 152L), sumHerkomst = c(41L, 41L, 41L, 41L, 41L), sumMoeiteRondk = c(43L, 43L, 43L, 43L, 43L), sumSoc = c(134L, 134L, 134L, 134L, 134L ), statusscore14 = c(1.01434966593117, 1.01434966593117, 1.01434966593117, 1.01434966593117, 1.01434966593117), meanBMI = c(24.3171488857854, 24.3171488857854, 24.3171488857854, 24.3171488857854, 24.3171488857854 ), meanAlcoholc = c(26.6535087719298, 26.6535087719298, 26.6535087719298, 26.6535087719298, 26.6535087719298), meanGroente = c(841.908270676692, 841.908270676692, 841.908270676692, 841.908270676692, 841.908270676692 ), meanWandelen = c(106.736842105263, 106.736842105263, 106.736842105263, 106.736842105263, 106.736842105263), meanSport = c(187.266666666667, 187.266666666667, 187.266666666667, 187.266666666667, 187.266666666667 ), sum_agegrp_1 = c(136L, 136L, 136L, 136L, 136L), sum_agegrp_2 = c(40L, 40L, 40L, 40L, 40L), sum_agegrp_3 = c(55L, 55L, 55L, 55L, 55L), sum_agegrp_4 = c(109L, 109L, 109L, 109L, 109L), sum_agegrp_5 = c(55L, 55L, 55L, 55L, 55L), sum_agegrp_6 = c(4L, 4L, 4L, 4L, 4L), n = c(17920L, 17920L, 17920L, 17920L, 17920L), pOpleidingHigh = c(0.24812030075188, 0.24812030075188, 0.24812030075188, 0.24812030075188, 0.24812030075188 )), .Names = c("id", "long", "lat", "order", "hole", "piece", "group", "X", "sumOpleidinghigh", "sumOpleidinglow", "sumBeperking", "sumOuderPersoon", "sumHerkomst", "sumMoeiteRondk", "sumSoc", "statusscore14", "meanBMI", "meanAlcoholc", "meanGroente", "meanWandelen", "meanSport", "sum_agegrp_1", "sum_agegrp_2", "sum_agegrp_3", "sum_agegrp_4", "sum_agegrp_5", "sum_agegrp_6", "n", "pOpleidingHigh" ), row.names = c(NA, 5L), class = "data.frame")

How can this be avoided?

  • Can you provide a sample of your data set (using dput())? – rcs Jun 10 '16 at 7:38
  • I reckon you have mixed object with piece for group – mdsumner Jun 10 '16 at 7:40
  • I have added a sample of the data with dput, never used it before so please let me if something should be different. – Keizer Jun 10 '16 at 7:44
  • This represents just one polygon, please provide a larger sample (maybe on pastebin.com with a link in the question, or somewhere else ...) – rcs Jun 10 '16 at 8:03
  • Yes, I added the first 100 rows on pastebin via this link: pastebin.com/p1r5Wu1R (I wanted to do the do multiple postal codes, however the second started at 2000 so it was not possible to place that on pastebin.com, hope this is okay as well?) – Keizer Jun 10 '16 at 8:30
2

I found the solution a couple of seconds ago, it had to do with the column order.I changed the numbers into a decreasing sequence (first these were completely mixed). Now I get the correct output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.