diff --git a/_freeze/posts/2023-10-11/index/execute-results/html.json b/_freeze/posts/2023-10-11/index/execute-results/html.json index fc5aa8c6..a3397a4c 100644 --- a/_freeze/posts/2023-10-11/index/execute-results/html.json +++ b/_freeze/posts/2023-10-11/index/execute-results/html.json @@ -1,7 +1,7 @@ { - "hash": "c5e833719d12d4b1ea2cd9a2871ad36b", + "hash": "4d9ef6f499b1f07cefe0853d38e8d793", "result": { - "markdown": "---\ntitle: \"Horizontal Legends in Base R\"\nauthor: \"Steven P. Sanderson II, MPH\"\ndate: \"2023-10-11\"\ncategories: [rtip, viz]\n---\n\n\n# Introduction\n\nCreating a horizontal legend in base R can be a useful skill when you want to label multiple categories in a plot without taking up too much vertical space. In this blog post, we'll explore various methods to create horizontal legends in R and provide examples with clear explanations.\n\n# Why Do We Need Horizontal Legends?\n\nVertical legends are great for smaller plots, but in larger visualizations, they can become a space-consuming eyesore. Horizontal legends, on the other hand, allow you to neatly label categories without cluttering the plot area. They are especially useful when you have many categories to label.\n\n# Using the `legend` Function\n\nThe most straightforward way to create a horizontal legend in base R is by using the `legend` function. Here's a simple example:\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Create a sample plot\nplot(1:5, col = 1:5, pch = 19)\n\n# Add a horizontal legend\nlegend(\"top\", legend = c(\"A\", \"B\", \"C\", \"D\", \"E\"), \n fill = 1:5, horiz = TRUE, x.intersp = 0.2)\n```\n\n::: {.cell-output-display}\n![](index_files/figure-html/unnamed-chunk-1-1.png){width=672}\n:::\n:::\n\n\nIn this code, we first create a basic scatter plot and then use the `legend` function to add a legend at the top of the plot (`\"top\"`). The `horiz = TRUE` argument specifies a horizontal legend.\n\n# Customizing the Horizontal Legend\n\nYou can further customize the horizontal legend to match your preferences. Here are some common parameters:\n\n- `x.intersp` controls the horizontal spacing between legend elements.\n- `inset` adjusts the distance of the legend from the plot.\n- `title` adds a title to the legend.\n\n```R\n# Customize the horizontal legend\nlegend(\"top\", legend = c(\"A\", \"B\", \"C\", \"D\", \"E\"), \n fill = 1:5, horiz = TRUE, x.intersp = 0.2, inset = 0.02, \n title = \"Categories\")\n```\n\n# Adding Multiple Horizontal Legends\n\nIn some cases, you might need multiple horizontal legends in a single plot. You can achieve this by specifying different locations for each legend.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Create a sample plot\nplot(1:5, col = 1:5, pch = 19)\n\n# Add two horizontal legends\nlegend(\"top\", legend = c(\"A\", \"B\", \"C\"), \n fill = 1:3, horiz = TRUE, x.intersp = 0.2, inset = 0.02,\n title = \"Top Legend\")\nlegend(\"bottom\", legend = c(\"D\", \"E\"), \n fill = 4:5, horiz = TRUE, x.intersp = 0.2, inset = 0.02,\n title = \"Bottom Legend\")\n```\n\n::: {.cell-output-display}\n![](index_files/figure-html/unnamed-chunk-2-1.png){width=672}\n:::\n:::\n\n\nIn this example, we add two horizontal legends at the top and bottom of the plot, each with its set of labels and colors.\n\n# Encourage Readers to Experiment\n\nCreating horizontal legends in base R is a versatile skill that you can use in various data visualization projects. I encourage you to experiment with different plot types, colors, and parameters to create the perfect horizontal legend for your specific needs. Don't be afraid to get creative and tailor your legends to make your plots more informative and visually appealing.\n\nBy following these simple steps and experimenting with your own plots, you'll be able to master the art of horizontal legends in R. So go ahead and give it a try! Your future visualizations will thank you for the extra clarity and elegance that horizontal legends provide. Happy coding!", + "markdown": "---\ntitle: \"Horizontal Legends in Base R\"\nauthor: \"Steven P. Sanderson II, MPH\"\ndate: \"2023-10-11\"\ncategories: [rtip, viz]\n---\n\n\n# Introduction\n\nCreating a horizontal legend in base R can be a useful skill when you want to label multiple categories in a plot without taking up too much vertical space. In this blog post, we'll explore various methods to create horizontal legends in R and provide examples with clear explanations.\n\n# Why Do We Need Horizontal Legends?\n\nVertical legends are great for smaller plots, but in larger visualizations, they can become a space-consuming eyesore. Horizontal legends, on the other hand, allow you to neatly label categories without cluttering the plot area. They are especially useful when you have many categories to label.\n\n# Using the `legend` Function\n\nThe most straightforward way to create a horizontal legend in base R is by using the `legend` function. Here's a simple example:\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Create a sample plot\nplot(1:5, col = 1:5, pch = 19)\n\n# Add a horizontal legend\nlegend(\"top\", legend = c(\"A\", \"B\", \"C\", \"D\", \"E\"), \n fill = 1:5, horiz = TRUE, x.intersp = 0.2)\n```\n\n::: {.cell-output-display}\n![](index_files/figure-html/unnamed-chunk-1-1.png){width=672}\n:::\n:::\n\n\nIn this code, we first create a basic scatter plot and then use the `legend` function to add a legend at the top of the plot (`\"top\"`). The `horiz = TRUE` argument specifies a horizontal legend.\n\n# Customizing the Horizontal Legend\n\nYou can further customize the horizontal legend to match your preferences. Here are some common parameters:\n\n- `x.intersp` controls the horizontal spacing between legend elements.\n- `inset` adjusts the distance of the legend from the plot.\n- `title` adds a title to the legend.\n\n```R\n# Customize the horizontal legend\nlegend(\"top\", legend = c(\"A\", \"B\", \"C\", \"D\", \"E\"), \n fill = 1:5, horiz = TRUE, x.intersp = 0.2, inset = 0.02, \n title = \"Categories\")\n```\n\n# Adding Multiple Horizontal Legends\n\nIn some cases, you might need multiple horizontal legends in a single plot. You can achieve this by specifying different locations for each legend.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Create a sample plot\nplot(1:5, col = 1:5, pch = 19)\n\n# Add two horizontal legends\nlegend(\"top\", legend = c(\"A\", \"B\", \"C\"), \n fill = 1:3, horiz = TRUE, x.intersp = 0.2, inset = 0.02,\n title = \"Top Legend\")\nlegend(\"bottom\", legend = c(\"D\", \"E\"), \n fill = 4:5, horiz = TRUE, x.intersp = 0.2, inset = 0.02,\n title = \"Bottom Legend\")\n```\n\n::: {.cell-output-display}\n![](index_files/figure-html/unnamed-chunk-2-1.png){width=672}\n:::\n:::\n\n\nIn this example, we add two horizontal legends at the top and bottom of the plot, each with its set of labels and colors.\n\n# Experiment\n\nCreating horizontal legends in base R is a versatile skill that you can use in various data visualization projects. I encourage you to experiment with different plot types, colors, and parameters to create the perfect horizontal legend for your specific needs. Don't be afraid to get creative and tailor your legends to make your plots more informative and visually appealing.\n\nBy following these simple steps and experimenting with your own plots, you'll be able to master the art of horizontal legends in R. So go ahead and give it a try! Your future visualizations will thank you for the extra clarity and elegance that horizontal legends provide. Happy coding!", "supporting": [ "index_files" ], diff --git a/docs/index.html b/docs/index.html index f719088e..c4546b3c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -209,7 +209,7 @@
Categories
-
+
diff --git a/docs/index.xml b/docs/index.xml index 968c6a29..5c9af9a7 100644 --- a/docs/index.xml +++ b/docs/index.xml @@ -277,8 +277,8 @@ font-style: inherit;">"Bottom Legend")

In this example, we add two horizontal legends at the top and bottom of the plot, each with its set of labels and colors.

-
-

Encourage Readers to Experiment

+
+

Experiment

Creating horizontal legends in base R is a versatile skill that you can use in various data visualization projects. I encourage you to experiment with different plot types, colors, and parameters to create the perfect horizontal legend for your specific needs. Don’t be afraid to get creative and tailor your legends to make your plots more informative and visually appealing.

By following these simple steps and experimenting with your own plots, you’ll be able to master the art of horizontal legends in R. So go ahead and give it a try! Your future visualizations will thank you for the extra clarity and elegance that horizontal legends provide. Happy coding!

diff --git a/docs/posts/2023-10-11/index.html b/docs/posts/2023-10-11/index.html index 3267c889..565eb03f 100644 --- a/docs/posts/2023-10-11/index.html +++ b/docs/posts/2023-10-11/index.html @@ -284,8 +284,8 @@

Adding Multiple Horizontal Legends

In this example, we add two horizontal legends at the top and bottom of the plot, each with its set of labels and colors.

-
-

Encourage Readers to Experiment

+
+

Experiment

Creating horizontal legends in base R is a versatile skill that you can use in various data visualization projects. I encourage you to experiment with different plot types, colors, and parameters to create the perfect horizontal legend for your specific needs. Don’t be afraid to get creative and tailor your legends to make your plots more informative and visually appealing.

By following these simple steps and experimenting with your own plots, you’ll be able to master the art of horizontal legends in R. So go ahead and give it a try! Your future visualizations will thank you for the extra clarity and elegance that horizontal legends provide. Happy coding!

diff --git a/docs/search.json b/docs/search.json index 9ec820bb..3750870a 100644 --- a/docs/search.json +++ b/docs/search.json @@ -3616,6 +3616,6 @@ "href": "posts/2023-10-11/index.html", "title": "Horizontal Legends in Base R", "section": "", - "text": "Introduction\nCreating a horizontal legend in base R can be a useful skill when you want to label multiple categories in a plot without taking up too much vertical space. In this blog post, we’ll explore various methods to create horizontal legends in R and provide examples with clear explanations.\n\n\nWhy Do We Need Horizontal Legends?\nVertical legends are great for smaller plots, but in larger visualizations, they can become a space-consuming eyesore. Horizontal legends, on the other hand, allow you to neatly label categories without cluttering the plot area. They are especially useful when you have many categories to label.\n\n\nUsing the legend Function\nThe most straightforward way to create a horizontal legend in base R is by using the legend function. Here’s a simple example:\n\n# Create a sample plot\nplot(1:5, col = 1:5, pch = 19)\n\n# Add a horizontal legend\nlegend(\"top\", legend = c(\"A\", \"B\", \"C\", \"D\", \"E\"), \n fill = 1:5, horiz = TRUE, x.intersp = 0.2)\n\n\n\n\nIn this code, we first create a basic scatter plot and then use the legend function to add a legend at the top of the plot (\"top\"). The horiz = TRUE argument specifies a horizontal legend.\n\n\nCustomizing the Horizontal Legend\nYou can further customize the horizontal legend to match your preferences. Here are some common parameters:\n\nx.intersp controls the horizontal spacing between legend elements.\ninset adjusts the distance of the legend from the plot.\ntitle adds a title to the legend.\n\n# Customize the horizontal legend\nlegend(\"top\", legend = c(\"A\", \"B\", \"C\", \"D\", \"E\"), \n fill = 1:5, horiz = TRUE, x.intersp = 0.2, inset = 0.02, \n title = \"Categories\")\n\n\nAdding Multiple Horizontal Legends\nIn some cases, you might need multiple horizontal legends in a single plot. You can achieve this by specifying different locations for each legend.\n\n# Create a sample plot\nplot(1:5, col = 1:5, pch = 19)\n\n# Add two horizontal legends\nlegend(\"top\", legend = c(\"A\", \"B\", \"C\"), \n fill = 1:3, horiz = TRUE, x.intersp = 0.2, inset = 0.02,\n title = \"Top Legend\")\nlegend(\"bottom\", legend = c(\"D\", \"E\"), \n fill = 4:5, horiz = TRUE, x.intersp = 0.2, inset = 0.02,\n title = \"Bottom Legend\")\n\n\n\n\nIn this example, we add two horizontal legends at the top and bottom of the plot, each with its set of labels and colors.\n\n\nEncourage Readers to Experiment\nCreating horizontal legends in base R is a versatile skill that you can use in various data visualization projects. I encourage you to experiment with different plot types, colors, and parameters to create the perfect horizontal legend for your specific needs. Don’t be afraid to get creative and tailor your legends to make your plots more informative and visually appealing.\nBy following these simple steps and experimenting with your own plots, you’ll be able to master the art of horizontal legends in R. So go ahead and give it a try! Your future visualizations will thank you for the extra clarity and elegance that horizontal legends provide. Happy coding!" + "text": "Introduction\nCreating a horizontal legend in base R can be a useful skill when you want to label multiple categories in a plot without taking up too much vertical space. In this blog post, we’ll explore various methods to create horizontal legends in R and provide examples with clear explanations.\n\n\nWhy Do We Need Horizontal Legends?\nVertical legends are great for smaller plots, but in larger visualizations, they can become a space-consuming eyesore. Horizontal legends, on the other hand, allow you to neatly label categories without cluttering the plot area. They are especially useful when you have many categories to label.\n\n\nUsing the legend Function\nThe most straightforward way to create a horizontal legend in base R is by using the legend function. Here’s a simple example:\n\n# Create a sample plot\nplot(1:5, col = 1:5, pch = 19)\n\n# Add a horizontal legend\nlegend(\"top\", legend = c(\"A\", \"B\", \"C\", \"D\", \"E\"), \n fill = 1:5, horiz = TRUE, x.intersp = 0.2)\n\n\n\n\nIn this code, we first create a basic scatter plot and then use the legend function to add a legend at the top of the plot (\"top\"). The horiz = TRUE argument specifies a horizontal legend.\n\n\nCustomizing the Horizontal Legend\nYou can further customize the horizontal legend to match your preferences. Here are some common parameters:\n\nx.intersp controls the horizontal spacing between legend elements.\ninset adjusts the distance of the legend from the plot.\ntitle adds a title to the legend.\n\n# Customize the horizontal legend\nlegend(\"top\", legend = c(\"A\", \"B\", \"C\", \"D\", \"E\"), \n fill = 1:5, horiz = TRUE, x.intersp = 0.2, inset = 0.02, \n title = \"Categories\")\n\n\nAdding Multiple Horizontal Legends\nIn some cases, you might need multiple horizontal legends in a single plot. You can achieve this by specifying different locations for each legend.\n\n# Create a sample plot\nplot(1:5, col = 1:5, pch = 19)\n\n# Add two horizontal legends\nlegend(\"top\", legend = c(\"A\", \"B\", \"C\"), \n fill = 1:3, horiz = TRUE, x.intersp = 0.2, inset = 0.02,\n title = \"Top Legend\")\nlegend(\"bottom\", legend = c(\"D\", \"E\"), \n fill = 4:5, horiz = TRUE, x.intersp = 0.2, inset = 0.02,\n title = \"Bottom Legend\")\n\n\n\n\nIn this example, we add two horizontal legends at the top and bottom of the plot, each with its set of labels and colors.\n\n\nExperiment\nCreating horizontal legends in base R is a versatile skill that you can use in various data visualization projects. I encourage you to experiment with different plot types, colors, and parameters to create the perfect horizontal legend for your specific needs. Don’t be afraid to get creative and tailor your legends to make your plots more informative and visually appealing.\nBy following these simple steps and experimenting with your own plots, you’ll be able to master the art of horizontal legends in R. So go ahead and give it a try! Your future visualizations will thank you for the extra clarity and elegance that horizontal legends provide. Happy coding!" } ] \ No newline at end of file diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 4ad66b10..7c23c5c4 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -10,7 +10,7 @@ https://www.spsanderson.com/steveondata/index.html - 2023-10-11T12:15:42.556Z + 2023-10-11T12:16:40.933Z https://www.spsanderson.com/steveondata/posts/rtip-2023-04-06/index.html @@ -478,6 +478,6 @@ https://www.spsanderson.com/steveondata/posts/2023-10-11/index.html - 2023-10-11T12:15:50.286Z + 2023-10-11T12:16:48.977Z diff --git a/posts/2023-10-11/index.qmd b/posts/2023-10-11/index.qmd index 8d410082..9c738819 100644 --- a/posts/2023-10-11/index.qmd +++ b/posts/2023-10-11/index.qmd @@ -62,7 +62,7 @@ legend("bottom", legend = c("D", "E"), In this example, we add two horizontal legends at the top and bottom of the plot, each with its set of labels and colors. -# Encourage Readers to Experiment +# Experiment Creating horizontal legends in base R is a versatile skill that you can use in various data visualization projects. I encourage you to experiment with different plot types, colors, and parameters to create the perfect horizontal legend for your specific needs. Don't be afraid to get creative and tailor your legends to make your plots more informative and visually appealing.