Get the App
SLTechnology News&Howtos  ›  Development  › 

How to adjust the position of ggplot2 legend legend.position

Shulou Source: shulou.com Published: 2022-06-01 04:56:11 10月05日 Update

Ggplot2 drawing process, controlling the position of the legend in the diagram using theme (legend.position) parameters

The corresponding settings for this parameter are as follows:

Legend.position

The position of legends ("none", "left", "right", "bottom", "top", or two-element numeric vector)

Where none represents a hidden legend, refer to https://www..com/article/383

Other types mean to control the specific position, including "left" left, "right" right, "bottom", "top", based on the drawing process https://www..com/article/92, modify theme (legend.position)

P_bottom=p+theme (legend.position = "bottom") print (p_bottom)

But mainly, legend.position can also be controlled by a numerical vector composed of two elements, mainly by setting the specific position of the legend in the middle of the picture, rather than the periphery of the picture. The size of the value is generally between 0 and 1, and exceeding the value often causes the legend to be hidden.

C (0.9, 0.7)

P_v=p+theme (legend.position = c (0.9)) print (pairv)

C (0.9) only a small half of the illustration appears

P_v=p+theme (legend.position = c (0.9) 1. 1) print (pairv)

C (0.9 Jue 1.2) the legend is completely beyond the drawing board and can be understandably hidden

If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Legend position adjustment numerical value knowledge process control drawing parameter picture industry different practical two between element content vector foundation size Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi NVidia MariaDB OPPO Reno Shulou Technology