ggplot2

How to reverse point size in ggplot?

眉间皱痕 提交于 2021-02-15 19:11:32
问题 Please, help me with this point. I need the positive values to be represented as small points and negative as large points. If I tape minus before size, the point sizes are right but the legend is changing: df=data.frame(x=rnorm(20),y=runif(20),z=rnorm(20)) ggplot(df,aes(x=x,y=y))+geom_point(aes(size=-z)) so that does not suite. 回答1: One solution would be to use scale_size() and set your own breaks and then labels in opposite direction. Changed range of z values to get better representation.

How to reverse point size in ggplot?

前提是你 提交于 2021-02-15 19:10:46
问题 Please, help me with this point. I need the positive values to be represented as small points and negative as large points. If I tape minus before size, the point sizes are right but the legend is changing: df=data.frame(x=rnorm(20),y=runif(20),z=rnorm(20)) ggplot(df,aes(x=x,y=y))+geom_point(aes(size=-z)) so that does not suite. 回答1: One solution would be to use scale_size() and set your own breaks and then labels in opposite direction. Changed range of z values to get better representation.

ggplot2 issue: graph text shown with weird unicode blocks

主宰稳场 提交于 2021-02-15 07:16:45
问题 I have got the following problem: When I plot anything with ggplot2 like this # Libraries library(ggplot2) # create data xValue <- 1:10 yValue <- cumsum(rnorm(10)) data <- data.frame(xValue,yValue) # Plot ggplot(data, aes(x=xValue, y=yValue)) + geom_line() The resulting graph looks like this where the text is shown in weir unicode blocks: ggplot2 graph with text issue These unicode blocks look like boxes with four numbers starting with two 0s like: # Example block ---- |00| |2C| ---- I

ggplot2 issue: graph text shown with weird unicode blocks

 ̄綄美尐妖づ 提交于 2021-02-15 07:15:12
问题 I have got the following problem: When I plot anything with ggplot2 like this # Libraries library(ggplot2) # create data xValue <- 1:10 yValue <- cumsum(rnorm(10)) data <- data.frame(xValue,yValue) # Plot ggplot(data, aes(x=xValue, y=yValue)) + geom_line() The resulting graph looks like this where the text is shown in weir unicode blocks: ggplot2 graph with text issue These unicode blocks look like boxes with four numbers starting with two 0s like: # Example block ---- |00| |2C| ---- I

ggplot2 order categorical stacked bars by proportions of y-axis

自古美人都是妖i 提交于 2021-02-15 04:53:05
问题 I have a data frame with categorical x-axis called Category and the yaxis is the Abundance, colored by Sequence. For each Category I am trying to reorder the stacks by the Abundance, so that it is easily visualized which sequence has the highest proportion at the bottom, to the lowest proportion at the top. Currently, I can make a bar graph like this: s<-"Sequence Abundance Category CAGTG 0.8 A CAGTG 0.2 B CAGTG 0.6 C CAGTG 0.3 D CAGTG 0.1 E GGGAC 0.1 A GGGAC 0.1 B GGGAC 0.3 C GGGAC 0.6 D

ggplot2 order categorical stacked bars by proportions of y-axis

给你一囗甜甜゛ 提交于 2021-02-15 04:51:37
问题 I have a data frame with categorical x-axis called Category and the yaxis is the Abundance, colored by Sequence. For each Category I am trying to reorder the stacks by the Abundance, so that it is easily visualized which sequence has the highest proportion at the bottom, to the lowest proportion at the top. Currently, I can make a bar graph like this: s<-"Sequence Abundance Category CAGTG 0.8 A CAGTG 0.2 B CAGTG 0.6 C CAGTG 0.3 D CAGTG 0.1 E GGGAC 0.1 A GGGAC 0.1 B GGGAC 0.3 C GGGAC 0.6 D

R ggplot2 Add today's date to the title

痞子三分冷 提交于 2021-02-13 17:34:21
问题 In principle, I'm sure this is straightforward.... How do I append today's date to my ggplot title? today.date <- Sys.Date() labs(title='Daily New COVID-19 Hospitalizations as of ', x=....) In other words, what's the R / ggplot syntax to append today.date to my plot title? Am I better off using ggtitle rather than labs for the title -- does that make it easier? Thank you! 回答1: Both with labs and ggtitle you can use function paste() as follows: labs(title = paste('Daily New COVID-19

How to control “count” in tooltip for ggplotly with filled bar plot in R

泄露秘密 提交于 2021-02-11 18:01:46
问题 Thanks in advance for any advice you can offer! I'm hoping to be able to relabel "count" in the tooltip for a public facing interactive plot. Here's a reproducible example: library(plotly) df <- data.frame(cat=c(rep("A", 5), rep("B", 7), rep("C", 10)), time=c(rep("Time1", 3), rep("Time2", 13), rep("Time3", 6))) ggplotly(ggplot(df, aes(x=time, fill=cat)) + geom_bar(position = "fill")) I know I can control the time and category labels in the tooltip with text=paste("Category:", cat, "Time:"

How to control “count” in tooltip for ggplotly with filled bar plot in R

浪尽此生 提交于 2021-02-11 18:01:05
问题 Thanks in advance for any advice you can offer! I'm hoping to be able to relabel "count" in the tooltip for a public facing interactive plot. Here's a reproducible example: library(plotly) df <- data.frame(cat=c(rep("A", 5), rep("B", 7), rep("C", 10)), time=c(rep("Time1", 3), rep("Time2", 13), rep("Time3", 6))) ggplotly(ggplot(df, aes(x=time, fill=cat)) + geom_bar(position = "fill")) I know I can control the time and category labels in the tooltip with text=paste("Category:", cat, "Time:"

gganimate: data present only in some frames

主宰稳场 提交于 2021-02-11 17:57:42
问题 I have a problem animating plots where data in some layers in present only in some of the frames. In the example below, I have a moving point that can be nicely animated along 9 frames. However, when I add another layer with a point present only in some of the frames, I get the following error: Error: time data must be the same class in all layers Example : require(data.table) require(ggplot2) require(gganimate) # 9 points along x=y; present at every time point dtP1 = data.table(x = 1:9, y =