{"id":3137,"date":"2023-07-19T01:08:41","date_gmt":"2023-07-19T01:08:41","guid":{"rendered":"https:\/\/statorials.org\/nl\/ggplot-weet-niet-hoe-om-te-gaan-met-ongelijke-dataklasse\/"},"modified":"2023-07-19T01:08:41","modified_gmt":"2023-07-19T01:08:41","slug":"ggplot-weet-niet-hoe-om-te-gaan-met-ongelijke-dataklasse","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/ggplot-weet-niet-hoe-om-te-gaan-met-ongelijke-dataklasse\/","title":{"rendered":"Oplossing: ggplot2 weet niet hoe om te gaan met ongelijke klassengegevens"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Een fout die je tegen kunt komen in R is:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>Error: ggplot2 doesn't know how to deal with data of class uneval\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Deze fout treedt meestal op wanneer u <strong>ggplot2<\/strong> probeert te gebruiken om twee gegevensframes tegelijk te plotten, maar het <strong>gegevensargument<\/strong> in de functie <strong>geom_line()<\/strong> niet kunt gebruiken.<\/span><\/p>\n<p> <span style=\"color: #000000;\">In deze tutorial wordt precies uitgelegd hoe u deze fout kunt oplossen.<\/span><\/p>\n<h2> <strong>Hoe de fout te reproduceren<\/strong><\/h2>\n<p> <span style=\"color: #000000;\">Laten we zeggen dat we twee dataframes in R hebben die het aantal verkopen op specifieke tijdstippen en op verschillende dagen weergeven:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#create first data frame\n<span style=\"color: #000000;\">df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (date=c(1, 1, 1, 2, 2, 2, 3, 3, 3),\n                 hour=c(1, 2, 3, 1, 2, 3, 1, 2, 3),\n                 sales=c(2, 5, 7, 5, 8, 12, 10, 14, 13))\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>head(df)\n\n  date hour sales\n1 1 1 2\n2 1 2 5\n3 1 3 7\n4 2 1 5\n5 2 2 8\n6 2 3 12\n\n<span style=\"color: #008080;\">#create second data frame\n<\/span>df_new &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (date=c(4, 4, 4, 5, 5, 5),\n                     hour=c(1, 2, 3, 1, 2, 3),\n                     sales=c(12, 13, 19, 15, 18, 20))\n\n<span style=\"color: #008080;\">#view data frame \n<\/span>head(df_new)\n\n  date hour sales\n1 4 1 12\n2 4 2 13\n3 4 3 19\n4 5 1 15\n5 5 2 18\n6 5 3 20<\/span><\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Laten we nu zeggen dat we een lijndiagram proberen te maken om de verkopen gegroepeerd op dag en uur te visualiseren, met de kleur blauw voor het eerste dataframe en rood voor het tweede dataframe:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #008080;\"><strong><span style=\"color: #000000;\"><span style=\"color: #008000;\">library<\/span> (ggplot2)<\/span>\n\n#attempt to create line chart\n<span style=\"color: #000000;\">ggplot(df, aes(x=hour, y=sales, group=date)) +\n  geom_line(color=' <span style=\"color: #ff0000;\">blue<\/span> ') +\n  geom_line(df_new, aes(x=hour, y=sales, group=date), color=' <span style=\"color: #ff0000;\">red<\/span> ')\n\nError: ggplot2 doesn't know how to deal with data of class uneval\n<\/span><\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">We ontvangen een foutmelding omdat we het <strong>data-<\/strong> argument in de tweede functie <strong>geom_line()<\/strong> niet hebben gebruikt.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Hoe u de fout kunt oplossen<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">De manier om deze fout op te lossen is door eenvoudigweg de gegevens in het tweede argument <strong>geom_line()<\/strong> in te voeren, zodat R weet welk dataframe we proberen te plotten.<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #008080;\"><strong><span style=\"color: #000000;\"><span style=\"color: #008000;\">library<\/span> (ggplot2)<\/span>\n\n#create line chart\n<span style=\"color: #000000;\">ggplot(df, aes(x=hour, y=sales, group=date)) +\n  geom_line(color=' <span style=\"color: #ff0000;\">blue<\/span> ') +\n  geom_line(data=df_new, aes(x=hour, y=sales, group=date), color=' <span style=\"color: #ff0000;\">red<\/span> ')<\/span><\/strong><\/span> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-26691 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/classe1.jpg\" alt=\"\" width=\"435\" height=\"437\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Merk op dat we het lijndiagram deze keer met succes en zonder fouten kunnen maken.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">In de volgende tutorials wordt uitgelegd hoe u andere veelvoorkomende fouten in R kunt oplossen:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/nl\/er-moet-een-foutdatum-van-herkomst-worden-opgegeven\/\" target=\"_blank\" rel=\"noopener\">Hoe op te lossen in R: fout in as.Date.numeric(x): &#8222;origin&#8220; moet worden opgegeven<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/r-fout-stripchart-standaard-ongeldige-plotmethode\/\" target=\"_blank\" rel=\"noopener\">Oplossing: Fout in stripchart.default(x1, \u2026): Ongeldige plotmethode<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/fout-in-evalpredvars-gegevens-env-object-niet-gevonden\/\" target=\"_blank\" rel=\"noopener\">Hoe op te lossen: fout in eval (predvars, data, env): object &#8218;x&#8216; niet gevonden<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Een fout die je tegen kunt komen in R is: Error: ggplot2 doesn&#8217;t know how to deal with data of class uneval Deze fout treedt meestal op wanneer u ggplot2 probeert te gebruiken om twee gegevensframes tegelijk te plotten, maar het gegevensargument in de functie geom_line() niet kunt gebruiken. In deze tutorial wordt precies uitgelegd [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-3137","post","type-post","status-publish","format-standard","hentry","category-gids"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Oplossing: ggplot2 weet niet hoe hij met ongelijke klassengegevens moet omgaan - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt uitgelegd hoe u de volgende fout in R kunt oplossen: ggplot2 weet niet hoe om te gaan met ongelijke klassengegevens.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/nl\/ggplot-weet-niet-hoe-om-te-gaan-met-ongelijke-dataklasse\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Oplossing: ggplot2 weet niet hoe hij met ongelijke klassengegevens moet omgaan - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt uitgelegd hoe u de volgende fout in R kunt oplossen: ggplot2 weet niet hoe om te gaan met ongelijke klassengegevens.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/ggplot-weet-niet-hoe-om-te-gaan-met-ongelijke-dataklasse\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-19T01:08:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/classe1.jpg\" \/>\n<meta name=\"author\" content=\"Dr.benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr.benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"2\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/ggplot-weet-niet-hoe-om-te-gaan-met-ongelijke-dataklasse\/\",\"url\":\"https:\/\/statorials.org\/nl\/ggplot-weet-niet-hoe-om-te-gaan-met-ongelijke-dataklasse\/\",\"name\":\"Oplossing: ggplot2 weet niet hoe hij met ongelijke klassengegevens moet omgaan - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-19T01:08:41+00:00\",\"dateModified\":\"2023-07-19T01:08:41+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt uitgelegd hoe u de volgende fout in R kunt oplossen: ggplot2 weet niet hoe om te gaan met ongelijke klassengegevens.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/ggplot-weet-niet-hoe-om-te-gaan-met-ongelijke-dataklasse\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/ggplot-weet-niet-hoe-om-te-gaan-met-ongelijke-dataklasse\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/ggplot-weet-niet-hoe-om-te-gaan-met-ongelijke-dataklasse\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Oplossing: ggplot2 weet niet hoe om te gaan met ongelijke klassengegevens\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/nl\/#website\",\"url\":\"https:\/\/statorials.org\/nl\/\",\"name\":\"Statorials\",\"description\":\"Uw gids voor statistische competentie\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/nl\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\",\"name\":\"Dr.benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr.benjamin anderson\"},\"description\":\"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder\",\"sameAs\":[\"http:\/\/statorials.org\/nl\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Oplossing: ggplot2 weet niet hoe hij met ongelijke klassengegevens moet omgaan - Statorials","description":"In deze tutorial wordt uitgelegd hoe u de volgende fout in R kunt oplossen: ggplot2 weet niet hoe om te gaan met ongelijke klassengegevens.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/statorials.org\/nl\/ggplot-weet-niet-hoe-om-te-gaan-met-ongelijke-dataklasse\/","og_locale":"de_DE","og_type":"article","og_title":"Oplossing: ggplot2 weet niet hoe hij met ongelijke klassengegevens moet omgaan - Statorials","og_description":"In deze tutorial wordt uitgelegd hoe u de volgende fout in R kunt oplossen: ggplot2 weet niet hoe om te gaan met ongelijke klassengegevens.","og_url":"https:\/\/statorials.org\/nl\/ggplot-weet-niet-hoe-om-te-gaan-met-ongelijke-dataklasse\/","og_site_name":"Statorials","article_published_time":"2023-07-19T01:08:41+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/classe1.jpg"}],"author":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr.benjamin anderson","Gesch\u00e4tzte Lesezeit":"2\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/nl\/ggplot-weet-niet-hoe-om-te-gaan-met-ongelijke-dataklasse\/","url":"https:\/\/statorials.org\/nl\/ggplot-weet-niet-hoe-om-te-gaan-met-ongelijke-dataklasse\/","name":"Oplossing: ggplot2 weet niet hoe hij met ongelijke klassengegevens moet omgaan - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-19T01:08:41+00:00","dateModified":"2023-07-19T01:08:41+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt uitgelegd hoe u de volgende fout in R kunt oplossen: ggplot2 weet niet hoe om te gaan met ongelijke klassengegevens.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/ggplot-weet-niet-hoe-om-te-gaan-met-ongelijke-dataklasse\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/ggplot-weet-niet-hoe-om-te-gaan-met-ongelijke-dataklasse\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/ggplot-weet-niet-hoe-om-te-gaan-met-ongelijke-dataklasse\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Oplossing: ggplot2 weet niet hoe om te gaan met ongelijke klassengegevens"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/nl\/#website","url":"https:\/\/statorials.org\/nl\/","name":"Statorials","description":"Uw gids voor statistische competentie","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/nl\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de"},{"@type":"Person","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219","name":"Dr.benjamin anderson","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/","url":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr.benjamin anderson"},"description":"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder","sameAs":["http:\/\/statorials.org\/nl"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/3137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/comments?post=3137"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/3137\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=3137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=3137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=3137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}