用阴影斑点包围点
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用阴影斑点包围点相关的知识,希望对你有一定的参考价值。
因此,我想制作一个可以为3个不同的组(汽车)提供积分的情节,但作为一般区域,就像这个草图上的斑点一样。理想情况下,在点所在的区域会有较暗的色调。有任何想法吗?
数据使用
structure(list(mpg = c(18, 14, 19, 26, 16, 15, 29, 23, 18, 15.5,
28, 26.5, 32.2, 32.4, 34), cylinders = c(6, 8, 4, 4, 6, 6, 4,
4, 6, 8, 4, 4, 4, 4, 4), displacement = c(232, 304, 122, 122,
258, 258, 97, 140, 171, 304, 97, 140, 108, 108, 108), horsepower = c(100,
150, 85, 80, 110, 110, 75, 83, 97, 120, 75, 72, 75, 75, 70),
weight = c(3288, 3672, 2310, 2451, 3632, 3730, 2171, 2639,
2984, 3962, 2155, 2565, 2265, 2350, 2245), acceleration = c(15.5,
11.5, 18.5, 16.5, 18, 19, 16, 17, 14.5, 13.9, 16.4, 13.6,
15.2, 16.8, 16.9), year = c(71, 73, 73, 74, 74, 75, 75, 75,
75, 76, 76, 76, 80, 81, 82), origin = c(1, 1, 1, 1, 1, 1,
3, 1, 1, 1, 3, 1, 3, 3, 3), name = structure(c(10L, 10L,
156L, 156L, 10L, 10L, 266L, 156L, 156L, 10L, 266L, 156L,
266L, 266L, 266L), .Label = c("amc ambassador brougham",
"amc ambassador dpl", "amc ambassador sst", "amc concord",
"amc concord d/l", "amc concord dl 6", "amc gremlin", "amc hornet",
"amc hornet sportabout (sw)", "amc matador", "amc matador (sw)",
"amc pacer", "amc pacer d/l", "amc rebel sst", "amc spirit dl",
"audi 100 ls", "audi 100ls", "audi 4000", "audi 5000", "audi 5000s (diesel)",
"audi fox", "bmw 2002", "bmw 320i", "buick century", "buick century 350",
"buick century limited", "buick century luxus (sw)", "buick century special",
"buick electra 225 custom", "buick estate wagon (sw)", "buick lesabre custom",
"buick opel isuzu deluxe", "buick regal sport coupe (turbo)",
"buick skyhawk", "buick skylark", "buick skylark 320", "buick skylark limited",
"cadillac eldorado", "cadillac seville", "capri ii", "chevroelt chevelle malibu",
"chevrolet bel air", "chevrolet camaro", "chevrolet caprice classic",
"chevrolet cavalier", "chevrolet cavalier 2-door", "chevrolet cavalier wagon",
"chevrolet chevelle concours (sw)", "chevrolet chevelle malibu",
"chevrolet chevelle malibu classic", "chevrolet chevette",
"chevrolet citation", "chevrolet concours", "chevrolet impala",
"chevrolet malibu", "chevrolet malibu classic (sw)", "chevrolet monte carlo",
"chevrolet monte carlo landau", "chevrolet monte carlo s",
"chevrolet monza 2+2", "chevrolet nova", "chevrolet nova custom",
"chevrolet vega", "chevrolet vega (sw)", "chevrolet vega 2300",
"chevrolet woody", "chevy c10", "chevy c20", "chevy s-10",
"chrysler cordoba", "chrysler lebaron medallion", "chrysler lebaron salon",
"chrysler lebaron town @ country (sw)", "chrysler new yorker brougham",
"chrysler newport royal", "datsun 1200", "datsun 200-sx",
"datsun 200sx", "datsun 210", "datsun 210 mpg", "datsun 280-zx",
"datsun 310", "datsun 310 gx", "datsun 510", "datsun 510 (sw)",
"datsun 510 hatchback", "datsun 610", "datsun 710", "datsun 810",
"datsun 810 maxima", "datsun b-210", "datsun b210", "datsun b210 gx",
"datsun f-10 hatchback", "datsun pl510", "dodge aries se",
"dodge aries wagon (sw)", "dodge aspen", "dodge aspen 6",
"dodge aspen se", "dodge challenger se", "dodge charger 2.2",
"dodge colt", "dodge colt (sw)", "dodge colt hardtop", "dodge colt hatchback custom",
"dodge colt m/m", "dodge coronet brougham", "dodge coronet custom",
"dodge coronet custom (sw)", "dodge d100", "dodge d200",
"dodge dart custom", "dodge diplomat", "dodge magnum xe",
"dodge monaco (sw)", "dodge monaco brougham", "dodge omni",
"dodge rampage", "dodge st. regis", "fiat 124 sport coupe",
"fiat 124 tc", "fiat 124b", "fiat 128", "fiat 131", "fiat strada custom",
"fiat x1.9", "ford country", "ford country squire (sw)",
"ford escort 2h", "ford escort 4w", "ford f108", "ford f250",
"ford fairmont", "ford fairmont (auto)", "ford fairmont (man)",
"ford fairmont 4", "ford fairmont futura", "ford fiesta",
"ford futura", "ford galaxie 500", "ford gran torino", "ford gran torino (sw)",
"ford granada", "ford granada ghia", "ford granada gl", "ford granada l",
"ford ltd", "ford ltd landau", "ford maverick", "ford mustang",
"ford mustang cobra", "ford mustang gl", "ford mustang ii",
"ford mustang ii 2+2", "ford pinto", "ford pinto (sw)", "ford pinto runabout",
"ford ranger", "ford thunderbird", "ford torino", "ford torino 500",
"hi 1200d", "honda accord", "honda accord cvcc", "honda accord lx",
"honda civic", "honda civic (auto)", "honda civic 1300",
"honda civic 1500 gl", "honda civic cvcc", "honda prelude",
"maxda glc deluxe", "maxda rx3", "mazda 626", "mazda glc",
"mazda glc 4", "mazda glc custom", "mazda glc custom l",
"mazda glc deluxe", "mazda rx-4", "mazda rx-7 gs", "mazda rx2 coupe",
"mercedes-benz 240d", "mercedes-benz 280s", "mercedes benz 300d",
"mercury capri 2000", "mercury capri v6", "mercury cougar brougham",
"mercury grand marquis", "mercury lynx l", "mercury marquis",
"mercury marquis brougham", "mercury monarch", "mercury monarch ghia",
"mercury zephyr", "mercury zephyr 6", "nissan stanza xe",
"oldsmobile cutlass ciera (diesel)", "oldsmobile cutlass ls",
"oldsmobile cutlass salon brougham", "oldsmobile cutlass supreme",
"oldsmobile delta 88 royale", "oldsmobile omega", "oldsmobile omega brougham",
"oldsmobile starfire sx", "oldsmobile vista cruiser", "opel 1900",
"opel manta", "peugeot 304", "peugeot 504", "peugeot 504 (sw)",
"peugeot 505s turbo diesel", "peugeot 604sl", "plymouth 'cuda 340",
"plymouth arrow gs", "plymouth champ", "plymouth cricket",
"plymouth custom suburb", "plymouth duster", "plymouth fury",
"plymouth fury gran sedan", "plymouth fury iii", "plymouth grand fury",
"plymouth horizon", "plymouth horizon 4", "plymouth horizon miser",
"plymouth horizon tc3", "plymouth reliant", "plymouth sapporo",
"plymouth satellite", "plymouth satellite custom", "plymouth satellite custom (sw)",
"plymouth satellite sebring", "plymouth valiant", "plymouth valiant custom",
"plymouth volare", "plymouth volare custom", "plymouth volare premier v8",
"pontiac astro", "pontiac catalina", "pontiac catalina brougham",
"pontiac firebird", "pontiac grand prix", "pontiac grand prix lj",
"pontiac j2000 se hatchback", "pontiac lemans v6", "pontiac phoenix",
"pontiac phoenix lj", "pontiac safari (sw)", "pontiac sunbird coupe",
"pontiac ventura sj", "renault 12 (sw)", "renault 12tl",
"renault 18i", "renault 5 gtl", "renault lecar deluxe", "saab 99e",
"saab 99gle", "saab 99le", "subaru", "subaru dl", "toyota carina",
"toyota celica gt", "toyota celica gt liftback", "toyota corolla",
"toyota corolla 1200", "toyota corolla 1600 (sw)", "toyota corolla liftback",
"toyota corolla tercel", "toyota corona", "toyota corona hardtop",
"toyota corona liftback", "toyota corona mark ii", "toyota cressida",
"toyota mark ii", "toyota starlet", "toyota tercel", "toyouta corona mark ii (sw)",
"triumph tr7 coupe", "vokswagen rabbit", "volkswagen 1131 deluxe sedan",
"volkswagen 411 (sw)", "volkswagen dasher", "volkswagen jetta",
"volkswagen model 111", "volkswagen rabbit", "volkswagen rabbit custom",
"volkswagen rabbit custom diesel", "volkswagen rabbit l",
"volkswagen scirocco", "volkswagen super beetle", "volkswagen type 3",
"volvo 144ea", "volvo 145e (sw)", "volvo 244dl", "volvo 245",
"volvo 264gl", "volvo diesel", "vw dasher (diesel)", "vw pickup",
"vw rabbit", "vw rabbit c (diesel)", "vw rabbit custom"), class = "factor")), class = "data.frame", row.names = c(NA,
-15L), .Names = c("mpg", "cylinders", "displacement", "horsepower",
"weight", "acceleration", "year", "origin", "name"))
代码我已经开始了
library(ggplot2)
ggplot(data = fast_cars, aes(x = year, y = horsepower, group = name, col=name)) + geom_point() +
ylab("Horsepower") +
ggtitle("Horsepower of the Three Most Common Cars over Time")
答案
您可以使用包geom_encircle
中的函数ggalt
来绘制“blob”(减少阴影区域的alpha
)。
library(ggplot2)
library(ggalt)
ggplot(fast_cars, aes(year, horsepower, fill = name)) +
geom_point(aes(shape = name)) +
geom_encircle(alpha = 0.2, show.legend = FALSE) +
theme_classic()
以上是关于用阴影斑点包围点的主要内容,如果未能解决你的问题,请参考以下文章