Ask Your Question
0

Why is ggplot displaying decimal values in the legend when the column contains numerical values?

asked 2021-09-27 11:00:00 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-03-12 20:00:00 +0000

david gravatar image

ggplot may display decimal values in the legend when the column contains numerical values because it is default behavior to display the actual values in the legend. To change this behavior, you can use the scale_*_format() function to format the legend labels to display as desired, such as removing decimal points or rounding to a specific number of digits. For example, using scale_fill_continuous() with the labels = scales::comma_format() argument will format the legend labels with comma separators.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-09-27 11:00:00 +0000

Seen: 10 times

Last updated: Mar 12 '22