在研究此答案时,我尝试geom_image()从ggimage包中绘制图像带,但无法使其正常工作。geom_image()修改图像的宽高比,但我不知道如何阻止它(或者是否有可能)。我也不清楚用什么单位size来衡量。从代码的行为方式来看,也许它在npc从0到1的坐标范围内,而不管ggplot2坐标系如何?
这是我使用的代码:
require(ggimage)
df_img <- data.frame(phase = c("Interphase", "Prophase", "Metaphase", "Anaphase", "Telophase"),
image = c("http://www.microbehunter.com/wp/wp-content/uploads/2009/lily_interphase.jpg",
"http://www.microbehunter.com/wp/wp-content/uploads/2009/lily_prophase.jpg",
"http://www.microbehunter.com/wp/wp-content/uploads/2009/lily_metaphase2.jpg",
"http://www.microbehunter.com/wp/wp-content/uploads/2009/lily_anaphase2.jpg",
"http://www.microbehunter.com/wp/wp-content/uploads/2009/lily_telophase.jpg"))
df_img$phase <- factor(df_img$phase, levels=df_img$phase)
ggplot(df_img, aes(x = phase, y = 0, image = image)) + geom_image(size = 0.18)
Run Code Online (Sandbox Code Playgroud)
这是结果图像:
这是图像的外观:
注意:这是一个专门关于ggimage行为的问题。我知道如何使用其他方法来生成正确的图像,例如通过使用draw_image()Cowplot。
我正在尝试在 ggplot2 中制作图表。我希望 x 轴显示 2.84 以及下面键入的序列。除了在 break() 中输入所有确切值之外,还有其他方法吗?我试过谷歌,但它没有解决我的问题。
scale_x_continuous(limits = c(1, 7), seq(1,7,by=0.5), name = "Number of
treatments")
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用cowplot包的draw_image()功能。我已经设法在图表中获取图像作为示例。
我无法弄清楚 xy 位置是如何工作的,我必须不断输入随机数,直到看到图像。
require(ggplot2) #required packages
require(cowplot)
require(magick)
p1 <- qplot(Sepal.Length, Sepal.Width, data = iris)
ggdraw(p1) +
draw_image(
"https://upload.wikimedia.org/wikipedia/en/7/77/EricCartman.png",
y = 0.2,
scale = 0.5
)
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议他们的运作规模如何?它看起来确实与图表的比例不同。
I am using the Tigris package to download shape files with the code,
options(tigris_class = "SF")
Run Code Online (Sandbox Code Playgroud)
While I can easily map polygons
ggplot(data=zctas) +
geom_sf(aes())
Run Code Online (Sandbox Code Playgroud)
I am struggling to create a marker/point instead of a filled polygon (for example, a shape -- like a circle inside a zctas) as the shape file I've pulled down from tigris does not have a lat/long for the x and y AES mapping. The shape file has a "geometry" column, and I am wondering …
我将生成一个ARIMA(0, 1, 1)包含60个观测值的序列。我希望它们对于所有移动平均参数(ma)都是严格正值,而该系列仍遵循一个ARIMA(0, 1, 1)过程。我可以使用arima.sim吗?
arima.sim(n=100, model=list(ma=-0.9, order=c(0, 1, 1)))
Run Code Online (Sandbox Code Playgroud)
这个命令给了我正负两个值。
我正在尝试使用ggridges包创建一个joyplot (基于ggplot2).一般的想法是,一个joyplot创建了精确缩放的堆积密度图.但是,我似乎无法使用加权密度生成其中一个.是否有一些方法可以在计算密钥套的创建中计算密度时采用抽样权重(加权密度)?
这里是该ggridges软件包文档的链接:https://cran.r-project.org/web/packages/ggridges/ggridges.pdf我知道很多基于ggplot的软件包可以接受额外的美学,但我不知道知道如何为这种类型的geom添加权重.
另外,这是ggplot中未加权的joyplot的示例.我试图将其转换为加权图,密度根据pweight加权.
# Load package, set seed
library(ggplot)
set.seed(1)
# Create an example dataset
dat <- data.frame(group = c(rep("A",100), rep("B",100)),
pweight = runif(200),
val = runif(200))
# Create an example of an unweighted joyplot
ggplot(dat, aes(x = val, y = group)) + geom_density_ridges(scale= 0.95)
Run Code Online (Sandbox Code Playgroud) 我有一个包含以下数据的数据框:
> data_graph
# A tibble: 12 x 4
# Groups: ATTPRO, ATTMAR [?]
x y group nb
<dbl> <dbl> <chr> <int>
1 0 0 1 1060
2 0 0 2 361
3 0 0 3 267
4 0 1 1 788
5 0 1 2 215
6 0 1 3 80
7 1 0 1 485
8 1 0 2 168
9 1 0 3 101
10 1 1 1 6306
11 1 1 2 1501
12 1 1 …Run Code Online (Sandbox Code Playgroud) 我试图在R中实现Brent-Salamin算法的变体.它适用于前25次迭代,但随后,它表现出意外,返回负面结果.
我想要实现的算法是:
initial values:
x_0 = 1; y_0 = 1/sqrt(2); z_0 = 1/2
x_n = (x_n-1 + y_n-1)/2
y_n = sqrt(x_n-1 * y_n-1)
z_n = z_n-1 - 2^n * (x_n^2-y_n^2)
p_n = (2 * x_n^2) / z_n
Run Code Online (Sandbox Code Playgroud)
其中n是当前迭代.
更精美的格式化公式是在这里.
我想出的代码是:
mypi <- function(n){
x = 1
y = 1/sqrt(2)
z = 1/2
iteration = 0
while(iteration < n){
iteration = iteration + 1
newx = (x + y) / 2
y = sqrt(x * y)
x …Run Code Online (Sandbox Code Playgroud) 我需要我的图表有一个深灰色主题来匹配演示风格。我还需要它们的高度是固定的,但宽度可能会根据 y 轴上标签的长度而有所不同。当我尝试导出或保存时,.jpg 或 .png 文件中总是有白色的边栏。
这是我用来创建图表的一些示例代码(此处有一些额外的主题控件对于简化示例来说是多余的,但生成的图表基本上就是我生成的):
library(ggplot2)
bar.font <- 8
title <- "Example"
l_labs <- c("")
x_labs <- c("A","B","C")
ests <- c(.5,.3,.2)
nerrs <- c(.05, .05, .05)
perrs <- nerrs
barchart.data <- data.frame(l_labs, x_labs, ests, nerrs, perrs)
p <- ggplot(barchart.data, aes(x=x_labs, y=ests*100)) +
geom_bar(stat="identity", color="#808080", position=position_dodge(), width=0.85, fill="#808080") +
geom_text(aes(y=ests*100+perrs*100+1.5, label=sprintf("%1.1f%%", 100*ests)), vjust=0.5, hjust=0, size=bar.font, color="white") +
geom_errorbar(aes(ymin=ests*100-nerrs*100, ymax=ests*100+perrs*100), width=.2, position=position_dodge(.9), color="white", size=0.25) +
labs(title=title, x="", y = "") + theme_classic() +
scale_y_continuous(expand = c(0,0),limits = c(0,115), breaks=c(0, 20, …Run Code Online (Sandbox Code Playgroud) r ×9
ggplot2 ×7
algorithm ×1
cowplot ×1
density-plot ×1
forecasting ×1
geospatial ×1
ggforce ×1
ggimage ×1
ggridges ×1
gplots ×1
pie-chart ×1
r-sf ×1
rstudio ×1
scatterpie ×1
tigris ×1