<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>indenkun</author_name>
  <author_url>https://blog.hatena.ne.jp/indenkun/</author_url>
  <blog_title>備忘ログ</blog_title>
  <blog_url>https://indenkun.hatenablog.com/</blog_url>
  <categories>
    <anon>R</anon>
    <anon>ggplot2</anon>
  </categories>
  <description>ggplot2パッケージの3.5.x以降で仕様変更があり、データ中に存在しない値を凡例に反映させるためには、以前の手法ではうまく行かなくなったので、現在動く手法のメモ。 例としてmtcarsデータの気筒数を因子型にしたものを用意して、グラフ化する。 library(ggplot2) mtcars &lt;- mtcars |&gt; dplyr::mutate(cyl = factor(cyl, levels = 4:8)) ggplot(mtcars) + geom_point(aes(x = mpg, y = disp, color = cyl)) データ中に、5気筒、7気筒がないので凡例には反映され…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Findenkun.hatenablog.com%2Fentry%2F2025%2F07%2F03%2F141729&quot; title=&quot;Rのggplot2でデータにない値を凡例に反映させるメモ2 - 備忘ログ&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url>https://cdn-ak.f.st-hatena.com/images/fotolife/i/indenkun/20250703/20250703141410.png</image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2025-07-03 14:17:29</published>
  <title>Rのggplot2でデータにない値を凡例に反映させるメモ2</title>
  <type>rich</type>
  <url>https://indenkun.hatenablog.com/entry/2025/07/03/141729</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
