how do you put text on different lines in ggplot

user1471980

My df looks like this:

 Product       Day      Month Total
Web Server, Applicatiion Server, Database Server, Middle Tier Tue 2015-01-01  10
Web Server, Application Server, Database Server, Middle Tier  Wed 2015-01-01    6
Web Server, Application Server, Database Server, Middle Tier  Wed 2015-02-01    6

I need to create a heat map in ggplot2 where I need to insert Product name as geom_text.

I have this so far:

ggplot(cal, aes(x=Month, y=Day, fill=Total)) +
   geom_tile() +
   scale_fill_gradient2(high="red",mid="green",low="yellow", 
       na.value="white", midpoint=mean(cal$Total, na.rm=T))+scale_x_date(labels = date_format("%b-%Y"), breaks = date_breaks("month"))+
       geom_text(aes(label=Product))

What happens is since there are multiple Product names separated by comma, when I do geom_text (aes(label=Product)), text is written on top of each other.

Is it possible put each Product name on different lines?

fabians

Just add "\n" to your "Product" labels wherever you need a line break:

library(ggplot2)
df <- data.frame(
  label=c("bla \n foo", "first line \n second line"),
  x = c(1, 2), y =c(1,2))
ggplot(df, aes(x=x, y=y, label=label)) + geom_text()

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How do you center text in Gitlab markdown?

From Dev

How do you select text in vim?

From Dev

how do you order Months in ggplot

From Dev

R - put ggplot grid lines in foreground

From Dev

How do you do new lines in .jade files?

From Dev

How do you fill Text in Canvas with Image?

From Dev

How do you add text in a Batch File?

From Dev

How do you replace multiple lines of text in path?

From Dev

How do you get Notepad++ to show separate lines when /r/n is in the text?

From Dev

How do you override default ggplot's aesthetics for points and lines?

From Dev

How do you put and control a checkbox in an NSTableView?

From Dev

How do you put vertical lines in between DataGrid Headers in C# WPF

From Dev

How do you centre align N lines of text

From Dev

How to put the text labels (keys) to the left of the lines in the legend?

From Dev

how do you parse text in grok

From Dev

How do I count text lines?

From Dev

How to set different colors for lines in ggplot

From Dev

How to use AsyncTask, where do I have to put the code lines?

From Dev

How do I count text lines?

From Dev

How to add text next to multiple lines in ggplot?

From Dev

How to put output to a different text file in flex

From Dev

How do I put text over the picture?

From Dev

How do you call variables put into a text file from a batch into a batch file?

From Dev

How do I put long text into shell?

From Dev

How do you put vertical lines in between DataGrid Headers in C# WPF

From Dev

How do you put 'weight' on different conditions in php while also keeping your results semi-random?

From Dev

How do you put a restriction on a variable?

From Dev

how to put mean lines in ggplot?

From Dev

How do you do fill_between two lines with different x-axis resolution?

Related Related

  1. 1

    How do you center text in Gitlab markdown?

  2. 2

    How do you select text in vim?

  3. 3

    how do you order Months in ggplot

  4. 4

    R - put ggplot grid lines in foreground

  5. 5

    How do you do new lines in .jade files?

  6. 6

    How do you fill Text in Canvas with Image?

  7. 7

    How do you add text in a Batch File?

  8. 8

    How do you replace multiple lines of text in path?

  9. 9

    How do you get Notepad++ to show separate lines when /r/n is in the text?

  10. 10

    How do you override default ggplot's aesthetics for points and lines?

  11. 11

    How do you put and control a checkbox in an NSTableView?

  12. 12

    How do you put vertical lines in between DataGrid Headers in C# WPF

  13. 13

    How do you centre align N lines of text

  14. 14

    How to put the text labels (keys) to the left of the lines in the legend?

  15. 15

    how do you parse text in grok

  16. 16

    How do I count text lines?

  17. 17

    How to set different colors for lines in ggplot

  18. 18

    How to use AsyncTask, where do I have to put the code lines?

  19. 19

    How do I count text lines?

  20. 20

    How to add text next to multiple lines in ggplot?

  21. 21

    How to put output to a different text file in flex

  22. 22

    How do I put text over the picture?

  23. 23

    How do you call variables put into a text file from a batch into a batch file?

  24. 24

    How do I put long text into shell?

  25. 25

    How do you put vertical lines in between DataGrid Headers in C# WPF

  26. 26

    How do you put 'weight' on different conditions in php while also keeping your results semi-random?

  27. 27

    How do you put a restriction on a variable?

  28. 28

    how to put mean lines in ggplot?

  29. 29

    How do you do fill_between two lines with different x-axis resolution?

HotTag

Archive