我有一个 React-Native 应用程序,我想使用并行编程(我想使用平板电脑的所有核心)。
我试过paralleljs和hamsters.js图书馆,但他们没有用。一个不支持 RN,另一个目前有一些 Blob 问题。
所以,我决定使用网络工作者。在对其进行了一些搜索(从 MDN 等)之后,我意识到我可能会单独使用网络工作者而不是所有这些库。但是我不能100%确定。还有其他为 RN 设计的库,比如 react-native-workers,但都有很多问题。
我的问题是如何使用纯 JS 代码在 React-Native 应用程序中使用多线程和/或并行编程?或者现在还不可能?
javascript multithreading web-worker react-native react-native-android
我有这个数据集:
top_bot_5_both <- structure(list(
name = structure(c(20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L,
11L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L),
.Label = c("Michele Bachmann", "Donald Trump", "Ted Cruz",
"Newt Gingrich", "Rick Santorum", "Terry McAuliffe",
"Nancy Pelosi", "Debbie Wasserman Schultz",
"Tammy Baldwin", "Joe Biden", "Rand Paul", "Jeb Bush",
"John Kasich", "Barack Obama", "Bill Clinton",
"Hillary Clinton", "Nathan Deal", "Tim Kaine",
"Rob Portman", "Sherrod Brown"),
class = "factor"),
Party = c("Democratic", "Republican", "Democratic", "Republican", "Democratic",
"Democratic", …Run Code Online (Sandbox Code Playgroud) df = data.frame(a = c(0, 0), b = c(17, 15),
c = c(35,37), d = c(55,57),
e = c(80, 85), x = c(1, 2),
w1 = c(20, 30), w2 = c(0.2, 0.3))
ggplot(df) +
geom_boxplot(aes(x = x, ymin = a, lower = b, middle = c, upper = d, ymax = e),
stat = "identity")
Run Code Online (Sandbox Code Playgroud)
我有一个数据框,包含箱图的每个分位数的值,(ae).是否可以使用列w1或w2来定义ggplot中箱线图的宽度?
我期望的结果是与使用varwidth中graphics::boxplot,但自定义的宽度.
graphics::boxplot(mpg~gear, mtcars, varwidth = T)
Run Code Online (Sandbox Code Playgroud)
不要认为这是重复的,因为看起来这个weight论点不起作用stat = identity.
我想使用经度和纬度点在 R 中绘制美国多个州的轮廓。现在我只能画出每个州的轮廓,所以我想知道如何画出美国多个州的轮廓(仅限外线)。
library(tidyverse)
library(knitr)
library(broom)
library(stringr)
library(modelr)
library(forcats)
library(ggmap)
states <- map_data("state")# %>% as_tibble()
counties <- map_data("county")
il_df <- filter(fifty_states, id == "illinois")
midwest <- subset(fifty_states, id %in% c("illinois", "indiana", "iowa",
"kansas", "michigan", "minnesota",
"missouri", "nebraska", "north dakota",
"ohio", "south dakota", "wisconsin"))
il_mid <- ggplot(data = midwest, mapping = aes(x = long, y = lat, group = group)) +
coord_fixed(1.3) +
geom_polygon(color = "black", fill = "gray")
il_mid
Run Code Online (Sandbox Code Playgroud)
我想知道如何绘制下图中的粉红色线。
我想绘制连续变量和分类变量(geom_boxplotwith ggplot2)之间关系的箱线图,这适用于几种情况(facet_wrap)。很简单:
data("CO2")
ggplot(CO2, aes(Treatment, uptake) ) +
geom_boxplot(aes(Treatment, uptake),
col="black", fill="white", alpha=0, width=.5) +
geom_point(col="black", size=1.2) +
facet_wrap(~Type, ncol=3, nrow=6, scales= "free_y") +
theme_bw() +
ylab("Uptake")
Run Code Online (Sandbox Code Playgroud)
This is quite nice with this toy dataset, but applied to my own data (where facet_wrap enables me to plot 18 different graphs) the y-axes are hardly readable, with varying number of y-ticks and varying spacing between them:
What could be a nice way to harmonize the …
我在 R 中使用 ggplot 创建了一个散点图:
ggplot(data, aes(x=x, y=y)) +
xlim(0,800) +
ylim(0,600) +
geom_point(colour="black") +
geom_path(aes(color="red")
Run Code Online (Sandbox Code Playgroud)
我想使用中心坐标、高度和宽度在该图上绘制一个叠加的椭圆(请不是置信区间椭圆)。
我已经尝试过draw.ellipseplotrix包中的函数,但这仅适用于R默认plot
函数创建的散点图。
有人知道如何在 ggplot 创建的散点图上绘制椭圆吗?
我想使用ggplot2在R中创建一个条形图,这样条形图就是透明的,允许背景图像可见,而图形的其余部分是不透明的并覆盖背景图像.
我可以将图像添加到背景中,如下所示,但我找不到只在条形图中显示背景图像的方法.基本上,我希望创建我在这里的反转.
library(ggplot2)
library(jpeg)
library(grid)
library(scales)
montage <- readJPEG("AcanthMontage.jpg")
mont <- rasterGrob(montage,
width = unit(1,"npc"),
height = unit(1,"npc"))
montplot <- ggplot(frequencyDF, aes(x=depth, y= perLiter)) +
annotation_custom(mont, -Inf, Inf, -Inf, Inf) +
scale_fill_continuous(guide = FALSE) +
geom_bar(stat = "identity", color="black", fill="white", alpha=0.5) +
coord_flip() +
scale_y_continuous(limits= c(0,1.25), expand = c(0, 0)) +
scale_x_continuous(limits= c(-1000,0), expand = c(0,0)) +
theme_bw() +
theme(text=element_text(size=16)) +
xlab("Depth (m)") +
ylab("Cells per Liter")
montplot
Run Code Online (Sandbox Code Playgroud)

我正在研究钻石数据集。我试图绘制克拉 x 价格,颜色代表清晰度。我得到了一个漂亮的调色板,但不是我想要的。它看起来更像是一个渐变,我想要彩虹,每个清晰度都有独特的颜色(我认为对于如此密集的数据图更容易)。
当我创建了我的基本情节时,一切正常。一旦我尝试添加scale_colour_gradientn(colours=rainbow())和任何变体,我就会收到错误消息。
#what works
ggplot(diamonds, aes(x=carat, y=price, color=clarity)) +
geom_point()
#what doesn't...
ggplot(diamonds, aes(x=carat, y=price, color=clarity)) +
geom_point() +
scale_colour_gradientn(colors=rainbow(7))
Run Code Online (Sandbox Code Playgroud)
我想看到颜色,但相反,我得到的反馈是离散值提供给连续比例。我将如何解决这个问题?
我正在尝试显示随着时间的推移构建的直方图。它将从 1952 年的数据开始,然后每年更新直方图,并不断增长。
这条路似乎很笨拙,我想transition_reveal随着时间的推移慢慢地揭示更多的数据。这似乎不起作用。
假设我从这个开始:
library(gapminder)
library(tidyverse)
library(gganimate)
ggplot(gapminder,
aes(lifeExp, fill = fct_rev(factor(year)), group = fct_rev(factor(year)))) +
geom_histogram(position = "stack", bins = 20) +
transition_reveal(year)
Run Code Online (Sandbox Code Playgroud)
这很失败。
我可以将一些东西与 混合在一起transition_layer,如下所示:
ggplot(gapminder, aes(lifeExp, fill = fct_rev(factor(year)))) +
geom_histogram(position = "stack", bins = 20,
data = filter(gapminder, year<= 1952)) +
geom_histogram(position = "stack", bins = 20,
data = filter(gapminder, year<= 1957)) +
geom_histogram(position = "stack", bins = 20,
data = filter(gapminder, year<= 1962)) +
geom_histogram(position = "stack", bins = 20, …Run Code Online (Sandbox Code Playgroud) 我想保存一些ggplot命令的规范供以后使用,因为我需要运行几个不同的图,这些图都具有一定的比例美感。
假设我想将其保存以供以后使用:
my.scale_aes <- scale_x_continuous(...) + scale_color_manual(...)
Run Code Online (Sandbox Code Playgroud)
当然,这将提示一条错误消息,表明您不能在没有直接ggplot()调用的情况下将ggproto对象一起添加。但是真的是这样吗?还有另一种方法可以将这些组件一起添加吗?
我在其他地方读到它与将元素添加在一起的不同方法有关:methods("+")我需要的东西与之有关,+.gg*但是我不知道如何实现它以及如何使其工作。
ggplot2 ×9
r ×9
ellipse ×1
geom-bar ×1
gganimate ×1
javascript ×1
react-native ×1
web-worker ×1