{"id":3793,"date":"2023-07-15T12:43:29","date_gmt":"2023-07-15T12:43:29","guid":{"rendered":"https:\/\/statorials.org\/nl\/restgrafiek-ggplot2\/"},"modified":"2023-07-15T12:43:29","modified_gmt":"2023-07-15T12:43:29","slug":"restgrafiek-ggplot2","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/restgrafiek-ggplot2\/","title":{"rendered":"Een restplot maken in ggplot2 (met voorbeeld)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\"><strong>Residuele plots<\/strong> worden gebruikt om te beoordelen of de <a href=\"https:\/\/statorials.org\/nl\/residu\/\" target=\"_blank\" rel=\"noopener\">residuen<\/a> van een regressiemodel normaal verdeeld zijn en of ze al dan niet <a href=\"https:\/\/statorials.org\/nl\/regressie-van-heteroscedasticiteit\/\" target=\"_blank\" rel=\"noopener\">heteroscedasticiteit<\/a> vertonen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Om een restplot in ggplot2 te maken, kunt u de volgende basissyntaxis gebruiken:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (ggplot2)\n\nggplot(model, aes(x = .fitted, y = .resid)) +\n  geom_point() +\n  geom_hline(yintercept = <span style=\"color: #008000;\">0<\/span> )\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Het volgende voorbeeld laat zien hoe u deze syntaxis in de praktijk kunt gebruiken.<\/span><\/p>\n<h2> <strong>Voorbeeld: een restplot maken in ggplot2<\/strong><\/h2>\n<p> <span style=\"color: #000000;\">Voor dit voorbeeld gebruiken we de <a href=\"https:\/\/statorials.org\/nl\/mtcars-r-gegevensset\/\" target=\"_blank\" rel=\"noopener\">mtcars-<\/a> dataset die in R is ingebouwd:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#view first six rows of mtcars dataset<\/span>\nhead(mtcars)\n                   mpg cyl disp hp drat wt qsec vs am gear carb\nMazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4\nMazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4\nDatsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1\nHornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1\nHornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2\nValiant 18.1 6 225 105 2.76 3,460 20.22 1 0 3 1<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Eerst zullen we een regressiemodel passen met <strong>mpg<\/strong> als de responsvariabele en <b>qsec<\/b> als de voorspellende variabele:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#fit regression model<\/span>\nmodel &lt;- lm(mpg ~ qsec, data=mtcars)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Vervolgens zullen we de volgende syntaxis gebruiken om een restplot in ggplot2 te maken:<\/span> <\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (ggplot2)\n\n<span style=\"color: #008080;\">#create residual plot\n<\/span>ggplot(model, aes(x = .fitted, y = .resid)) +\n  geom_point() +\n  geom_hline(yintercept = <span style=\"color: #008000;\">0<\/span> )<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-30786\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/ajustement1.jpg\" alt=\"restplot in ggplot2\" width=\"569\" height=\"440\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Op de x-as worden de gefitte waarden weergegeven en op de y-as de residuen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">De residuen lijken willekeurig verspreid rond nul te zijn zonder duidelijk patroon, wat aangeeft dat aan de aanname van homoscedasticiteit is voldaan.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Met andere woorden: de <a href=\"https:\/\/statorials.org\/nl\/hoe-regressiecoefficienten-te-interpreteren\/\" target=\"_blank\" rel=\"noopener\">co\u00ebffici\u00ebnten<\/a> van het regressiemodel moeten betrouwbaar zijn en we hoeven geen enkele <a href=\"https:\/\/statorials.org\/nl\/transformeer-gegevens-in-r\/\" target=\"_blank\" rel=\"noopener\">transformatie<\/a> op de gegevens uit te voeren.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Merk ook op dat we de functie <strong>labs()<\/strong> kunnen gebruiken om een titel en aslabels aan de restplot toe te voegen:<\/span> <\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (ggplot2)\n\n<span style=\"color: #008080;\">#create residual plot with title and axis labels\n<\/span>ggplot(model, aes(x = .fitted, y = .resid)) +\n  geom_point() +\n  geom_hline(yintercept = <span style=\"color: #008000;\">0<\/span> ) +\n  labs(title=' <span style=\"color: #ff0000;\">Residual vs. Fitted Values Plot<\/span> ', x=' <span style=\"color: #ff0000;\">Fitted Values<\/span> ', y=' <span style=\"color: #ff0000;\">Residuals<\/span> ')<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-30787\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/ajustement2.jpg\" alt=\"ggplot2 die residuen uitzet versus aangepaste waarden met aslabels\" width=\"532\" height=\"406\" srcset=\"\" sizes=\"auto, \"><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Aanvullende bronnen<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">In de volgende tutorials wordt uitgelegd hoe u andere veelvoorkomende taken in R kunt uitvoeren:<\/span><\/p>\n<p><a href=\"https:\/\/statorials.org\/nl\/residuen-gestandaardiseerd-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe gestandaardiseerde residuen in R te berekenen<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/residuen-in-r-gestudentiseerd\/\" target=\"_blank\" rel=\"noopener\">Hoe gestudentiseerde residuen in R te berekenen<\/a><br \/> <a href=\"https:\/\/statorials.org\/nl\/histogram-van-residuen-in-r\/\" target=\"_blank\" rel=\"noopener\">Hoe maak je een histogram van residuen in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Residuele plots worden gebruikt om te beoordelen of de residuen van een regressiemodel normaal verdeeld zijn en of ze al dan niet heteroscedasticiteit vertonen. Om een restplot in ggplot2 te maken, kunt u de volgende basissyntaxis gebruiken: library (ggplot2) ggplot(model, aes(x = .fitted, y = .resid)) + geom_point() + geom_hline(yintercept = 0 ) Het volgende [&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-3793","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>Een restplot maken in ggplot2 (met voorbeeld) - Statorials<\/title>\n<meta name=\"description\" content=\"In deze tutorial wordt met een voorbeeld uitgelegd hoe u een restplot in ggplot2 maakt.\" \/>\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\/restgrafiek-ggplot2\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Een restplot maken in ggplot2 (met voorbeeld) - Statorials\" \/>\n<meta property=\"og:description\" content=\"In deze tutorial wordt met een voorbeeld uitgelegd hoe u een restplot in ggplot2 maakt.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/restgrafiek-ggplot2\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-15T12:43:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/ajustement1.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\/restgrafiek-ggplot2\/\",\"url\":\"https:\/\/statorials.org\/nl\/restgrafiek-ggplot2\/\",\"name\":\"Een restplot maken in ggplot2 (met voorbeeld) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-15T12:43:29+00:00\",\"dateModified\":\"2023-07-15T12:43:29+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"In deze tutorial wordt met een voorbeeld uitgelegd hoe u een restplot in ggplot2 maakt.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/restgrafiek-ggplot2\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/restgrafiek-ggplot2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/restgrafiek-ggplot2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Een restplot maken in ggplot2 (met voorbeeld)\"}]},{\"@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":"Een restplot maken in ggplot2 (met voorbeeld) - Statorials","description":"In deze tutorial wordt met een voorbeeld uitgelegd hoe u een restplot in ggplot2 maakt.","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\/restgrafiek-ggplot2\/","og_locale":"de_DE","og_type":"article","og_title":"Een restplot maken in ggplot2 (met voorbeeld) - Statorials","og_description":"In deze tutorial wordt met een voorbeeld uitgelegd hoe u een restplot in ggplot2 maakt.","og_url":"https:\/\/statorials.org\/nl\/restgrafiek-ggplot2\/","og_site_name":"Statorials","article_published_time":"2023-07-15T12:43:29+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/ajustement1.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\/restgrafiek-ggplot2\/","url":"https:\/\/statorials.org\/nl\/restgrafiek-ggplot2\/","name":"Een restplot maken in ggplot2 (met voorbeeld) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-15T12:43:29+00:00","dateModified":"2023-07-15T12:43:29+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"In deze tutorial wordt met een voorbeeld uitgelegd hoe u een restplot in ggplot2 maakt.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/restgrafiek-ggplot2\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/restgrafiek-ggplot2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/restgrafiek-ggplot2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Een restplot maken in ggplot2 (met voorbeeld)"}]},{"@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\/3793","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=3793"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/3793\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=3793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=3793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=3793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}